Databases Reporting with SQL Working with Text Concatenating Text

Cosmin Iuga
Cosmin Iuga
2,058 Points

I'm so lost here. :(

So lost here. Please help:

SELECT first_name ||" "|| last_name ||" "|| email AS "Full Name", to_field AS "To" FROM patrons;

2 Answers

Sean T. Unwin
MOD
Sean T. Unwin
Treehouse Moderator 28,388 Points

In the previous lesson, right before this Challenge, there a quick note about using single vs double quotes. You need to understand when to use which. The key is to use single quotes for String literals, whereas double quotes are used for identifiers (I've found this is optional in many cases, at least with MS SQL Server and MySQL).

There is no reason to alias email as Full Name. Don't alias this field at all, actually.

The resulting String concatenation is to be aliased as to_field. This will be used as the value for the 'To' field when creating an email. We don't really care where the value is going to be used, we only need to know the alias to name it as.

We also need to include the angle brackets before and after the email address.

So pass this step:

  • change your double quotes to single when designating the spaces between the words
  • Remove the comma right before to_field and replace it with AS. It should look like AS to_field (Again, the double quotes are optional on the alias assignment)
  • Remove the AS "To"
  • Add the angled brackets to surround the email address.

I hope this helps and g'luck.

Pascal Breitrück
Pascal Breitrück
Pro Student 3,204 Points

Ahh ok, nice2know . I have only tried the challeng without to check the course videos ;D . Thanks for the Information . I will change it .

Pascal Breitrück
PRO
Pascal Breitrück
Pro Student 3,204 Points

Hey my Friend try this. :D

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

Sean T. Unwin
Sean T. Unwin
Treehouse Moderator 28,388 Points

Single quotes should be used on String literals. This Challenge will pass with the doubles, but most database engines will fail when doing this in a real scenario. So we may as well get used to doing it correctly. :-)