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 Reporting with SQL Working with Text Concatenating Text

Concatenate/ Alias help

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.

My answer: SELECT first_name || last_name || email AS to_field FROM patrons;

I am getting this question wrong what am I doing wrong, could someone explain please?

4 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Try including the angle brackets < > around the email address in your answer. The format needs to look exactly like as indicated in the challenge question.

Good luck :)

I rewrote my answer as the following like you suggested:

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

I am still not getting it correct but thank you for your help, if you could suggest something else I will try again

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

You just need a little extra concatenatoon. Use the concaentation operator every time youuse an angle bracket. Actually, you may also need to add the angle brackets as a string so SQL will recognise it and format the Alas accordingly.

For example.

"<" || column_name || ">"  

I rewrote my answer as such: SELECT <first_name> || <last_name> || <email> AS to_field FROM patrons; I still am getting it wrong I'm not sure what it is

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Okay. Let's look again at the format of the "to_field" you need to replicate.

Andrew Chalkley <andrew@teamtreehouse.com>

You have a first name, followed by a space. Followed by the last name, another space... followed by the email address in those "angle brackets", see?

So each new field, and each new empty space is being combined into the single Aliased field which is then output to the screen.

To output an empty space, you'd do

|| " " ||

The answer's there. You just need to work out where to put all the pieces together like a Jigsaw Puzzle! Good luck :-)

In words, that makes sense to me so I have re written the formula as such: SELECT first_name || " " || last_name || " " || <email> AS to_field FROM patrons;

But I'm still getting this wrong

Frosty Lindberg
Frosty Lindberg
4,793 Points

You need to concatenate the brackets, without spaces, not just throw them around the name of the column you're hoping to change. Every character you're adding needs to be concatenated separately -- <email> isn't a column in the table and so it will error on you.

You're almost there!