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

Donnie Driskell
Donnie Driskell
2,243 Points

Reporting with SQL 1 of 2 : can't solve after many attempts

Challenge Question: In the library database there's a patrons table listing all the users of the library. The columns are id, first_name, last_name, address, email, library_id and zip_code. Generate a list of strings that are in the following format: Andrew Chalkley andrew@teamtreehouse.com. Concatenate the first name, last name and email address for all users. Alias it to to_field. This will be used in the "To" field in email marketing.

My answer (incorrect), but as close as I can get. SELECT first_name, last_name, email FROM patrons ORDER BY first_name||""||last_name||""|| email;

I don't understand the "Alias it to "to_field" when there is no column for that.

I would appreciate any feedback. Thanks Donnie

Donnie Driskell
Donnie Driskell
2,243 Points

Thank you Steven for that tip. I also did some other online searching and this is the best I can do for now. But, the query still returns "Bummer! Your query needs didn't retrieve the emails in the correct format."

However, the returns look good to me - so I am at a loss of what I am doing wrong. I have tried like about 10 queries and the one here is the only one that will at least return the table like I want it:

SELECT first_name||" "||last_name||" <"||email||">" AS to_field FROM patrons;

Here is what it returns: (and it says that I still have the incorrect format) ?? Note: I had to add the numbers in the comment so the list would be in order -- ignore the numbers. This is not in final answer.

to_field

  1. Andrew Chalkley andrew@teamtreehouse.com
  2. Dave McFarland dave@teamtreehouse.com
  3. Alena Holligan alena@teamtreehouse.com
  4. Michael Poley michael@teamtreehouse.com

5 Answers

Steven Parker
Steven Parker
229,644 Points

An "alias" is a virtual column name. This is often useful when you create a new column by combining things, such as here using concatenation. And all the concatenation will occur in the SELECT clause, by the way. And you will not need ORDER BY for this challenge.

Donnie Driskell
Donnie Driskell
2,243 Points

Thank you Steven for that tip. I also did some other online searching and this is the best I can do for now. But, the query still returns "Bummer! Your query needs didn't retrieve the emails in the correct format."

However, the returns look good to me - so I am at a loss of what I am doing wrong. I have tried like about 10 queries and the one here is the only one that will at least return the table like I want it:

SELECT first_name||" "||last_name||" <"||email||">" AS to_field FROM patrons;

Here is what it returns: (and it says that I still have the incorrect format) ?? Note: I had to add the numbers in the comment so the list would be in order -- ignore the numbers. This is not in final answer.

to_field

  1. Andrew Chalkley andrew@teamtreehouse.com
  2. Dave McFarland dave@teamtreehouse.com
  3. Alena Holligan alena@teamtreehouse.com
  4. Michael Poley michael@teamtreehouse.com
Steven Parker
Steven Parker
229,644 Points

Please provide a link to the course page and I'll see if I can give you a specific fix.

Steven Parker
Steven Parker
229,644 Points

I copied your query line from your previous message, pasted it directly into the challenge, and it passed!

It looked OK to me to start with, so I'm baffled about why you still get an error.

Try it again, and if it's still happening you may need to forward this one on to the Support staff.

Donnie Driskell
Donnie Driskell
2,243 Points

Wow ! I went back to the blank challenge Question and pasted same string in -- Yep, -- it worked. Now that is strange. -- Thanks (mabye browser needed to be refreshed) Donnie

SELECT first_name || " " || last_name || " <" || email || ">" AS to_field FROM patrons;