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

users table SQL code challenge

the question is asks me to select the username first_name and last_name columns and to give them alias from the users table. so i wrote the following.

SELECT username "Username", last_name "Last Name", first_name "First Name" FROM users;

the question is returned as a fail asking me if I selected the 'users' table? I did, I checked the spelling. I don't know why this question will not pass. I even added the AS for alias in and that did not fix the issue.

4 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Eric, I think the only problem here is the order that you are selecting the columns in :)

SELECT username "Username", first_name "First Name", last_name "Last Name" FROM users;

you have to be kidding me. that was exactly it. so much for being able to rearrange the columns the way you want.

Thank you for your help.

True, that definitely could be the problem as well. Your answer might have to be in the same exact order they expect it to be. It’s kind of a bummer, the script that evaluates the answer should be more flexible, as the answer would still be correct no matter what order you put the columns that you are selecting. It should evaluate the end result I guess.

Hello! Can you provide the exact SQL script you wrote?

I know double quotes (“”) aren’t used much in SQL, instead we use single quotes (‘’).

It should be something like this:

SELECT first_name AS personsFirstName, last_name AS personsLastName FROM users

personsFirstName and personsLastName are my alias.

Notice I didn’t wrap the alias in single quotes, it’s not really necessary in this case. But if you do, it would work anyway. So that would look like this:

SELECT first_name AS ‘personsFirstName’, last_name AS ‘personsLastName’ FROM users

Single quotes are usually used when you are specifying value to a column (field) when querying.

Example: Select first_name FROM users WHERE last_name = ‘Washington’

That will return everyone whose last name is Washington.

the instructor said you have to add "" when you have a phrase that is not a single word alias. he mentioned you also don't have to put the AS for alias, just doing the "" is shorthand for alias. he did mention that MicrosoftSQL uses ' ' instead of "".

The reason I am failing the question is that it does not recognize the table I am pulling the data from. it is supposed to pull from the users table, and that's what I wrote in but it does not recognize it.

the SQL code I wrote is exactly what I entered in the original message.

thanks for any support I do appreciate the help. this is day 2 for me, so I am still really new at all this.

  • I recommend not wrapping your alias in any quotes; that could result in some kind of wacky execution or most likely an error.

Oh ok. Didn’t even know you can use two separate words as an alias. That’s a new one for me. Did the instructions specify you how to name the alias for each column? For example, did it tell you to give the column first_name the alias of “userName”? Sometimes it expects you to enter a given name. Also check for any misspelled variable names. The names of each table column (first_name, last_name) and table name (users) have to be spelled as given.