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

Amos Wu
Amos Wu
1,086 Points

I'm having trouble displaying the "<" and ">" around the email.

The first part of my query looks like:

SELECT first_name || " " || last_name || " <" || email || "> " AS to_field.... etc.

However, although the first and last names do show up with the appropriate spacing between them, the email doesn't appear at all, nor does the "<>" that is supposed to surround it. I have no idea what I'm doing wrong at all.

Please explain when convenient! Thank you!

3 Answers

Steven Parker
Steven Parker
231,248 Points

:point_right: Your SQL looks good so far.

Except for the minor point of the extra space after the close angle (">"). Those challenges can be really picky about string contents!

It might help if you post the entire SQL along with a link to the challenge page itself. The problem may be with a part of the line you haven't shown yet.

Amos Wu
Amos Wu
1,086 Points

Thanks for the quick response! Here's the link to the challenge page:

https://teamtreehouse.com/library/reporting-with-sql/working-with-text/concatenating-text

Here's my query:

SELECT first_name || " " || last_name || " <" || email || "> " AS to_field FROM patrons WHERE first_name = "Andrew" AND last_name = "Chalkley";

Steven Parker
Steven Parker
231,248 Points

:point_right: The challenge says to do this "for all users".

So remove your "WHERE" clause.
And don't forget to remove that extra space after the ">" — the challenge doesn't like that!

Also, even when you get it right you still won't see the email portion in the output. It's probably some HTML encoding bug.

Amos Wu
Amos Wu
1,086 Points

WOW didn't see that part of the question haha...

Hm this time the full names of everybody in "patrons" showed up, but the emails are still missing though.

-edited, added query and resulting report-

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

to_field Andrew Chalkley Dave McFarland Alena Holligan Michael Poley

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

But there's still the problem that it;s trying to find the email part of the string but it;s not finding. But the emails are in a differnt format.

I tried to solve that with this

SELECT first_name || " " || last_name || " <" || LOWER(first_name) || "@teamtreehouse.com" ||"> " AS to_field FROM patrons;

But no joy. We need the spaces too as this is how the example is presented in the question.

Steven Parker
Steven Parker
231,248 Points

Amos Wu, see my caveats about the extra space and the bug about the email in the output above. :arrow_heading_up:

Once you get rid of that extra space, you'll have it:

SELECT first_name || " " || last_name || " <" || email || ">" AS to_field FROM patrons;
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

It's been a little while since I did any SQL but I'm baffled lol

SELECT first_name || " " || last_name || " " || "<" || LOWER(first_name) || "@teamtreehouse.com" ||">" AS to_field FROM patrons;

This should work.

Steven Parker
Steven Parker
231,248 Points

Jonathan, the email might be made up from the name, but you can't count on it. You have to use the email field to be sure.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Amos,

I'd want to see the link to the challenge this refers to but I'm interested as to whether you need to concatenate a new sting between first_name and last_name. Do the other fields need to be aliased?

Try

SELECT first_name || " " || last_name || " <" || email || "> " AS to_field FROM databaseName  (I'm guessing this last bit)
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Oh yes by all means take the email field but the data is andrew.chalkley@teamtreehouse.com rather than

Generate a list of strings that are in the following format: Andrew Chalkley <andrew@teamtreehouse.com>. 

Which is what throws me. :)

Amos Wu
Amos Wu
1,086 Points

SOLVED IT!

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

I deleted the extra spaces around the "<" and ">", added another section of concatenation before "<" which was " ", and voila. Thanks for helping me through! I was spending an hour staring at the exercise... haha

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Great job, Amos!

Clearly that;s the answer the task was looking for but in actuality there;s more than one way to solve the problem.

Because including the email field like you did there doesn't actually change the format of the email string. The email in the date is in a first_name.last_name format rather than in a first_name format which is what baffles me.

Anyway, great job on passing! :-)

Steven Parker
Steven Parker
231,248 Points

Actually, having the space and the angle together was a good idea. You get the same result concatenating them, but combining two literal strings programmatically seems a bit silly.

And for Jonathan, the email might be made up from the name, but you can't count on it. You have to rely on the email field to be sure.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I thought i was being quite creative by concatenating the first_name in the LOWER function and using the @teamtreehouse string of the email. But like I say... different answers solve the problem but not for this code challenge which often wants something specific :-)