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 trialJeremy Pzygode
4,499 PointsReporting with SQL Challenge Task 1 out of 2
This is the challenge:
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.
This is what I input:
SELECT first_name || " " || last_name || " " || email AS to_field FROM patrons;
This is the error: Bummer! You're missing the angle brackets around the email address.
I have no clue how to add angle brackets. This wasn't taught in the lesson.
8 Answers
Jack Harrison-Sherlock
6,002 PointsTry this:
SELECT first_name || " " || last_name || " <" || email || ">"
AS "to_field"
FROM patrons;
Renaud Granier
5,420 PointsI had the same problem, this answer solved it. It is the good answer. Thx Sherlock! ;-)
Aaren Isabel
6,842 PointsThanks, Jack. What in the world do the greater than/ lesss than signs mean?
Derek Gannon
Courses Plus Student 1,140 PointsThanks for this. Thought I was screwing it up!
Laura Dumitru
9,818 PointsThis question was way harder than what was presented in the lesson.
Nemat Rahimov
Courses Plus Student 1,043 PointsSELECT first_name || " " || last_name || " " || "<"|| email || ">" AS to_field FROM patrons
Avi Tsipshtein
7,461 PointsHi Andrew,
The issue in challenge 1 out of 2 (concateantaion in sql) is not solved yet. I even tried to replace the < and > symbols with their HTML code like this:
Bummer! Your query needs didn't retireve the emails in the correct format. Get Help
> select last_name || ' ' || first_name || " <" || email || ">" as to_field from patrons;
to_field
Chalkley Andrew <andrew.chalkley@teamtreehouse.com>
McFarland Dave <dave.mcfarland@teamtreehouse.com>
Holligan Alena <alena.holligan@teamtreehouse.com>
Poley Michael <michael.poley@teamtreehouse.com>
looks like the output is correct but I still get an error.
Thanks,
Andrew Chalkley
Treehouse Guest TeacherYep. Please use a less than sign <
and a greater than sign >
Amir Cisija
2,901 PointsSELECT first_name || " " || last_name || " " || "< "|| email || ">" AS "to_field" FROM patrons;
It doesn't work for me, can someone tell me what is wrong?
Andrew Chalkley
Treehouse Guest TeacherAre you still having an issue? What error are you seeing?
Maryam Naz
3,636 PointsSELECT first_name || " " || last_name || " <" || email ||'>' AS to_field FROM patrons;
Ken Alger
Treehouse TeacherJeremy;
It sounds like you are wanting to concatenate characters together in a result. The Adding Text Columns Together video introduces us to the concatenation operator ||
, or double pipes. On Windows keyboards, the pipe character is typically Shift + \
.
You can concatenate characters into your field results in addition to simple things like spaces to impact formatting by including it inside quotes during the concatenation process. For example, to include a space between two field you could use first_field || ' ' || second_field
.
Hope that provides some direction, but if you are still stuck, please post back.
Happy coding,
Ken
Jeremy Pzygode
4,499 PointsI updated the question. Still don't know how to do it. I've rewatched the lesson multiple times to no avail.
Jason Anello
Courses Plus Student 94,610 PointsAs Ken mentioned, you can concatenate whatever characters you need.
With the sql you've posted, you're concatenating only a space between the last name and the email:
last_name || " " || email
Based on the required format, there needs to be a space and then a left angle bracket. So you only need to add that to the string.
Like this:
last_name || " <" || email
So after the last name, there will be a space, then a left angle bracket followed by the email address.
Then you would need to concatenate a right angle bracket after the email to complete the required formatting.
Jeremy Pzygode
4,499 PointsHey Jason,
I tried what you suggested and typed:
SELECT first_name || " " || last_name || " <" || email || "> " || AS to_field FROM patrons;
This still didn't work for me, I go this message:
SQL Error: near "AS": syntax error
Am I missing something?
Jason Anello
Courses Plus Student 94,610 PointsYou have an extra set of double pipes right before the AS keyword which you can remove since you're not concatenating anything else.
Also, I would remove the space that you have after the right angle bracket and only concatenate the right angle bracket. This way you don't have a trailing space at the end of this. I'm not sure either if it would pass the challenge with that trailing space.
Jeremy Pzygode
4,499 PointsAlright so I fixed what you said and I passed the challenge:
SELECT first_name || " " || last_name || " <" || email || ">" AS to_field FROM patrons;
This is what was generated:
to_field
Andrew Chalkley
Dave McFarland
Alena Holligan
Michael Poley
Do you know why the <email> portion is missing from the run results? I thought it was a requirement for it to show in the run results.
Jason Anello
Courses Plus Student 94,610 PointsCongrats on passing the challenge.
I don't know why it's missing but I think it should be there.
Do you have a link to the challenge?
Maybe Andrew Chalkley knows why.
Andrew Chalkley
Treehouse Guest TeacherOur console output (since it's HTML) doesn't correctly escape the less than and greater than symbols. I've opened a ticket and our development team should be able to take a look and fix it. Sorry for the confusion this causes.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Jeremy,
Can you link to the challenge you're on?