Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

how to retrieve the name and description columns from the products table with the aliases given?

i have tried these options: SELECT NAME AS "PRODUCT NAME", DESCRIPTION AS "PRODUCT DESCRIPTION" FROM PRODUCTS

SELECT name AS "PRODUCT NAME", description AS "PRODUCT DESCRIPTION" FROM PRODUCTS

2 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Jessica! To query a database and retrieve data from a database, you could use "AS" clause to assign aliases to the selected fields. This is the syntax for it:

Alias Column Syntax

SELECT column_name AS alias_name
FROM table_name;

Alias Table Syntax

SELECT column_name(s)
FROM table_name AS alias_name;

I hope it helped! (:

Michelle Yuan
Michelle Yuan
329 Points

I also tried. They don't work. Don't know why.

We're back in our e-commerce database. There's a products table with the columns id, name, description and price. Can you retrieve both the name and description aliased as "Product Name" and "Product Description".

that is the task that I was given. I have tried everything and nothing seems to work??

Shouldn't it be: SELECT product_name AS "PRODUCT NAME", product_description AS "PRODUCT DESCRIPTION" FROM products

Ari Misha
Ari Misha
19,323 Points

Hiya there! The correct syntax should be like this:

SELECT name AS "Product Name", description AS "Product Description" FROM products;