Reputation: 9
Write a query to concatenate staff id with first 3 characters from the staff name. Display with an alias as official_mail and order the results in ascending order.
my code:
select staff_id as official_mail
from Staff
order by official_mail;
how to write first 3 characters?
Upvotes: 0
Views: 2059
Reputation: 6088
For MySQL/MSSQL
SELECT CONCAT(staff_id,SUBSTRING(staff_name,1,3)) AS official_mail
FROM Staff
ORDER BY official_mail;
Live Demo
Upvotes: 1