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

Zachary Wheeler
Zachary Wheeler
1,157 Points

Reporting to SQL Challenge 3 Task 1

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

I'm having a hard time understanding the instructions on this challenge. I'm not sure what it is asking me to alias? Am i simply using SELECT and FROM commands like in the video or the others also?

2 Answers

Steven Parker
Steven Parker
231,248 Points

This query will use a SELECT and a FROM clause.

But the SELECT will be a bit involved, requiring the concatenation of a mix of data fields with literal strings, plus a column alias for the completed string.

This will be a chance to apply things you learned in the last few videos to a practical situation that's a bit different from any of the video examples. But the instructor and I are both betting you can figure it out.

Zachary Wheeler
Zachary Wheeler
1,157 Points

SELECT first_name AS "Andrew" || last_name AS "Chalkley" || email AS "andrew@teamtreehouse.com" FROM patrons AS to_field;

Here is what I have down currently. 1. Do I have the concatenations in the right spot and 2. Are the to_field it's asking for in the right area? I wasn't sure which column I was supposed to alias as to_field. was it each one within the selection like name, and email?

Let me know what needs to be fixed.

Thanks!

Steven Parker
Steven Parker
231,248 Points

Ok, here's a few more hints:

  • an alias (AS name) must follow the field(s) or literal(s) it is being applied to
  • all fields, with or without aliases, that are part of the SELECT clause will come before the FROM clause
  • parts of the sample string shown in the challenge should not appear as literals in the query
  • the query should use table fields to create a composite string that has the format of the sample
  • you can tell from the sample that the query will probably use the first_name, last_name, and email fields
  • the fields will need to be concatenated with literal strings where spacing and/or symbols are needed
Aananya Vyas
Aananya Vyas
20,157 Points

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

try this

Steven Parker
Steven Parker
231,248 Points

Aananya Vyas, I think most folks get a better learning experience by solving an issue themselves with a few hints than just being shown the answer. After 23 days, I'd hope Zachary has solved this (even though he did not select a "best answer"), but it might be a bit of a "spoiler" for others who have not completed this task themselves yet.