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 trialjames white
78,399 PointsSQL Error: no such column: first_name [RESOLVED]
Why isn't this a valid column name?
Link to challenge: https://teamtreehouse.com/library/reporting-with-sql/working-with-text/concatenating-text
Challenge Task 1 of 2
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
Figured it out.
It WAS a valid column name as long as you use 'FROM patrons'
so it knows which table the SELECT statement is referring to:
SELECT first_name || ' ' || last_name || ' <' || email || '>' AS to_field FROM patrons;
Now I'm having trouble with the second part of the challenge:
Challenge Task 2 of 2
In an eCommerce database there's a customers table.
There is an id, nickname, street, city, state, zip, country and user_id columns.
Concatenate the street, city, state, zip and country in the following format. Street, City, State Zip. Country e.g. 34 NE 12 st, Portland, OR 97129. USA. Alias the concatenated string as address
The SQL I tried was:
SELECT street || ', ' || city || ', ' || state || ' ' || zip || '. ' || country AS address FROM customers;
It gives me an error:
SQL Error: no such column: street
So this seems to be a different issue than the first part of the challenge
because I am using 'FROM customers' at the end of the query
but maybe that FROM part is getting cutoff somehow?
7 Answers
Andrew Winkler
37,739 PointsI FIGURED BOTH SOLUTIONS OUT!!!
Challenge One:
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.
SELECT first_name || ' ' || last_name || ' <' || email || '>'
AS to_field FROM patrons;
Challenge Two:
In an ecommerce database there's a addresses table. There is an id, nickname, street, city, state, zip, country and user_id columns. Concatenate the street, city, state, zip and country in the following format. Street, City, State Zip. Country e.g. 34 NE 12 st, Portland, OR 97129. USA. Alias the concatenated string as address
SELECT street || ", " || city || ", " || state || " " || zip || ". " || country
AS address FROM addresses;
The secound solution requires very strange formatting. Read the error messages if you're stuggling. Then tinker.
Zulma Feliciano
3,223 PointsI got in touch with the instructor, and he said the wrong table name was given; should have been addresses table. Issue has been corrected.
Giulio Vannini
21,922 PointsUse double quotes:
SELECT street || ", " || city || ", " || state || " " || zip || ". " || country AS address FROM customers;
However it returns a long list of errors and a NOT FOUND on the bottom!
I guess that needs just to be fixed :)
Zulma Feliciano
3,223 PointsHaving the same exact issue.
George Lambert
40,818 PointsI'm also getting error messages for what I believe is the correct query
james white
78,399 PointsThanks Zulma for contacting the instructor.
Thanks Andrew..yes I agree.
The answer to the second part of the challenge does require some 'requires very strange formatting' indeed!
I have marked Andrew's answer as Best Answer.
Andrew Winkler
37,739 PointsThank you. It's very much appreciated. I hope to be a forum moderator someday... cough shameless plug Andrew Chalkley cough, cough
Xander Hall
1,881 PointsWhere did you get those "<" & ">" signs from?
Charlie Harcourt
8,046 PointsIt was part of the email statement e.g first_name last_name < andrew@teamtreehouse.com > the '<' and '>' are for the start and end of the email address.
So that's why in the code we write || '<' || email || '>'
This is to display the '<' and the email address with a closing '>' .
:)
PRINAL PATEL
3,975 PointsPRINAL PATEL
3,975 PointsBecause of customers. Instead of customers; you should typed in addresses;