﻿ SQL: Display the unique designations for the employees

SQL Exercise: Display the unique designations for the employees

SQL employee Database: Exercise-3 with Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

3. From the following table, write a SQL query to find the unique designations of the employees. Return job name.

Sample table: employees

Pictorial Presentation:

Sample Solution:

``````SELECT DISTINCT job_name
FROM employees;
``````

Sample Output:

``` job_name
-----------
CLERK
SALESMAN
MANAGER
PRESIDENT
ANALYST
(5 rows)
```

Explanation:

The said query in SQL that retrieves all distinct (unique) values in the "job_name" column of the 'employees' table .

The DISTINCT keyword eliminates duplicate values from the result set, so this query will only return a list of unique job names that are stored in the 'employees' table.

Relational Algebra Expression:

Relational Algebra Tree:

Practice Online

Sample Database: employee

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

Previous SQL Exercise: Find the salaries of all employees.
Next SQL Exercise: Employee names and salaries are increased by 15% in \$.

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