﻿ SQL: Produce the output of employees name and job name

# 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

Pictorial Presentation:

Sample Solution:

``````SELECT emp_name|| '   ' ||job_name AS "Employee & Job"
FROM employees ;
``````

Sample Output:

```   Employee & Job
---------------------
KAYLING   PRESIDENT
BLAZE   MANAGER
CLARE   MANAGER
JONAS   MANAGER
SCARLET   ANALYST
FRANK   ANALYST
SANDRINE   CLERK
TUCKER   SALESMAN
JULIUS   CLERK
MARKER   CLERK
(14 rows)
```

Explanation:

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".

## Practice Online

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:

Input:

```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;
```

Output:

```COMPANY_ID   EMPLOYEE
1            Anna, Bill
2            Carol, Dave
```

Database: PostgreSQL

Ref: https://bit.ly/2XTiRjq

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