0

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?

4
  • 1
    Please specify database you're using in tags Commented Mar 27, 2018 at 8:49
  • 1
    Hint: LEFT(), SUBSTR(), SUBSTRING(). Commented Mar 27, 2018 at 8:49
  • Column staff_id's data type? Commented Mar 27, 2018 at 8:55
  • Which DBMS are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ... Commented Mar 27, 2018 at 11:02

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Product specific answer to a question with no dbms specified. At least tell us which dbms this is for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.