SQL Exercise: Produce the output of employees name and job name
SQL employee Database: Exercise-5 with Solution
[An editor is available at the bottom of the page to write and execute the scripts.]
5. From the following table, write a SQL query to list the employee's name and job name as a format of "Employee & Job".
Sample table: employees
SELECT emp_name|| ' ' ||job_name AS "Employee & Job" FROM employees ;
Employee & Job --------------------- KAYLING PRESIDENT BLAZE MANAGER CLARE MANAGER JONAS MANAGER SCARLET ANALYST FRANK ANALYST SANDRINE CLERK ADELYN SALESMAN WADE SALESMAN MADDEN SALESMAN TUCKER SALESMAN ADNRES CLERK JULIUS CLERK MARKER CLERK (14 rows)
The provided query in SQL that retrieves a result set that includes a list of concatenated strings, where each string represents an employee name and job name separated by a space character from the 'employees' table.
The concatenation is performed using the concatenation operator || and a space character (' ') to separate the employee name and job name and the newly created column aliased as "Employee & Job".
Sample Database: employee
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Employee names and salaries are increased by 15% in $.
Next SQL Exercise: Produce the output of employees.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
Concatenate strings of a string field in a PostgreSQL 'group by' query:
ID COMPANY_ID EMPLOYEE 1 1 Anna 2 1 Bill 3 2 Carol 4 2 Dave
SELECT company_id, string_agg(employee, ', ') FROM mytable GROUP BY company_id;
COMPANY_ID EMPLOYEE 1 Anna, Bill 2 Carol, Dave
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook