Select Unique - SQL

To select unique values from a column in SQL, you can use the DISTINCT keyword within the SELECT statement. The DISTINCT keyword eliminates duplicate values from the result set.

SQL
SELECT DISTINCT column_name
FROM table_name;
  • SELECT DISTINCT: This specifies that you want to retrieve unique values from the specified column(s).
  • column_name: This is the name of the column from which you want to retrieve unique values.
  • table_name: This is the name of the table from which you are retrieving data.
Example
SELECT DISTINCT department_id
FROM employees;

This SQL statement retrieves unique department IDs from the employees table, eliminating any duplicates.

If you want to retrieve unique combinations of values from multiple columns, you can use the DISTINCT keyword with multiple column names separated by commas:

SQL
SELECT DISTINCT column1, column2
FROM table_name;
Example
SELECT DISTINCT department_id, job_id
FROM employees;

This SQL statement retrieves unique combinations of department IDs and job IDs from the employees table, eliminating any duplicates.