w3resource

PostgreSQL Basic SELECT Statement: Get unique department ID from employee table


2. Write a query to get a unique department ID from employee table.

Sample Solution:

Code:

SELECT DISTINCT department_id 
FROM employees;

Sample table: employees

Output:

pg_exercises=# SELECT DISTINCT department_id 
pg_exercises-# FROM employees;

 department_id
---------------
            90
            20
           100
            40
           110
            80
            70
            50
            60
            30
            10
             0
(12 rows)

Practice Online



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

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming