w3resource

Basic SELECT statement: Get the name of all the employees from employees table

MySQL Basic Select Statement: Exercise-14 with Solution

Write a query to get the name (for example Ellen Abel, Sundar Ande etc.) of all the employees from employees table.

Sample table: employees


Code:

-- Concatenating the first_name and last_name columns with a space in between
SELECT CONCAT(first_name, ' ', last_name) 'Employee Name' 
-- Selecting data from the employees table
FROM employees;

Explanation:

  • This SQL query concatenates the first_name and last_name columns of the employees table, with a space in between.
  • The CONCAT() function is used to concatenate the values of the specified columns or strings.
  • The result of this concatenation is displayed in the result set with the alias "Employee Name".

Pictorial Presentation of the above query


Result :


MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query to calculate 171*214+625.
Next: Write a query to get first name of all employees table after removing white spaces from both side.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.