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

Oskar Pihlak
Oskar Pihlak
2,094 Points

SUBSTRING problem

In an ecommerce database there's a customers table with id, username, first_name, last_name, password, email and phone columns. Create a report from the customers table that shows their first initial of their first name and alias it as initial. Select their last name too.

There's something wrong with your SQL statement. Please review your code and try again.

SELECT SUBSTR(first_name, 1,1) AS initial || " & " || last_name FROM customers;

1 Answer

Amir Eskandari
Amir Eskandari
9,153 Points

Hi Oskar,

I may have misunderstood your question so I will provide two answers.

If you are trying to select the initial as one column and the last name as another, you can do it like this:

SELECT 
SUBSTR(first_name, 1,1) AS initial,
last_name 
FROM customers;

If you wanted to select both the first initial and the full last name together while giving the column an alias of "initial" it would look something like this:

SELECT CONCAT(SUBSTR(first_name, 1, 1), ' ', last_name ) AS initial

I hope this helps!