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

What should be the SQL code for challenge one? I have tried different ways but it keeps giving me an error

First of all I need to make first_name, last_name and email in concatenation then need to Alias the name to "to_field", Is that right?

Tommy Gebru
Tommy Gebru
30,164 Points

This one stumped me a few times as well Sevdiye

I went ahead and formatted it be easier to read

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

Also if you have a question for a particular challenge be sure to keep one good conversation going instead of creating new Forum Posts in the Community forums

3 Answers

Maxwell Newberry
Maxwell Newberry
7,693 Points
SELECT `first_name` || " " || `last_name` || " <" || `email` || ">" AS `to_field` FROM `patrons`;

In this challenge, your objective is to demonstrate knowledge of how to properly concatenate different columns and use the AS keyword to properly give these concatenated columns an alias. The important thing to note is that between my concatenated columns, I've in included a space between the first_name and last_name columns, as well as surrounded the email column in < > symbols because SQL does not automatically do that.

Andrew talks more about this in Adding Column Text Together.

bright chibuike
bright chibuike
3,245 Points

yes i have also tried this but keeps having series of pup up errors SELECT first_name||""||last_name||""||'<'||email||'>' AS "to_field" FROM patrons;

Tommy Gebru
Tommy Gebru
30,164 Points

Try to format your code using the Markdown Cheatsheet it helps everyone observe the syntax and whitespace of your code

Wrap your code with 3 backticks (```) on the line before and after. If you specify the language 
after the first set of backticks, that'll help us with syntax highlighting.

          ```html
          <p>This is code!</p>
          ```

bright chibuike I suspect that your quotation marks is interfering giving you errors, but you can share again or edit your code here

bright chibuike
bright chibuike
3,245 Points

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 query

yes i have also tried this but keeps having series of pup up errors SELECT first_name||""||last_name||""||'<'||email||'>' AS "to_field" FROM patrons;