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 trialLacie Norris
3,327 PointsChanging the cases of strings: Code Challenge 2 SQL
In the library database there's a patrons table with the columns id, first_name, last_name, address, email, library_id, and zip_code. The library is generating new library cards that will display the full name and their library ID. The full name needs to have the last name in all caps. Create a report with two columns of results, one is an alias of full_name the second being the library_id.
SELECT LOWER(first_name) AS "library_id" UPPER(last_name) AS "full_name", FROM patrons;
SQL Error: near "UPPER": syntax error
Lacie Norris
3,327 PointsSELECT LOWER(first_name) AS "library_id", UPPER(last_name) AS "full_name" FROM patrons;
Bummer! Expected results to look like "Andrew CHALKLEY", "MCL1001" not "andrew", "CHALKLEY".
7 Answers
Lacie Norris
3,327 PointsI figured it out, thank you! SELECT first_name ||' '|| UPPER(last_name) AS "full_name", library_id FROM patrons;
Vipin Singh
15,268 Pointsselect first_name ||' '|| UPPER(last_name) AS full_name, library_id from patrons;
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsThink from the end:
The library is generating new library cards that will display the full name and their library ID.
You need to have SQL table somewhat like this:
full_name | library_id
----------------|-------------|
Andrew Chalkey | MCL1001
So first of all you need to write something like this:
SELECT ... AS full_name, library_id FROM patrons
Now think what to put in ....
Full name is "first_name" + "last_name".
But also last_name has to be in CAPS,because of
The full name needs to have the last name in all caps
So
"first_name" + "UPPER(last_name)"
Then we also probably should put space between first and last_name, otherwise it will be strange full_name, right?
"first_name" + " " + "UPPER(last_name)"
All that is left is to connect them using proper LOGICAL operator and put everything into ...
specified above and write final query.
Tried my best to give you hints:) Hope it was helpful.
Joy Manuel
6,464 PointsThe double quotes work also. SELECT first_name || " " || UPPER(last_name) AS full_name, library_id FROM patrons;
Alex Davis
35,050 PointsIt's because you have LOWER(first_name). It forces the entire name to be lower case.
Dan Epstein
3,233 PointsBuilding on the concatenation knowledge from the former challenge is the key here.
Laura Dumitru
9,818 PointsThis chapter's challenges is really testing my patience.
Joseph Wasden
20,406 PointsJoseph Wasden
20,406 PointsYou are missing a comma after your first alias. Inspect after "library_id" for the error.
Add the comma, and you should be set.