Rasika Dewangan
Rasika Dewangan

Reputation: 9

concatenate sql

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

Answers (1)

Jay Shankar Gupta
Jay Shankar Gupta

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

http://sqlfiddle.com/#!9/f9c13b/1

Upvotes: 1

Related Questions