SQL SELECT UNIQUE and SELECT DISTINCT
Retrieving unique data from a table is a common SQL requirement. Both SELECT UNIQUE and SELECT DISTINCT serve this purpose, with slight historical differences. Let us clarify their roles, syntax, and use cases.
Complete Python Course with Advance topics:-
SQL Tutorial:-
UNIQUE vs DISTINCT: The History
SELECT UNIQUE is older syntax from Oracle. The ANSI SQL standard later defined SELECT DISTINCT as the official keyword. Oracle adopted DISTINCT for compliance but kept UNIQUE for backward compatibility. Both do the same thing, but DISTINCT is the preferred, standardized syntax.
Syntax
-- Legacy (Oracle)
SELECT UNIQUE column_name FROM table_name;
-- Standard (recommended)
SELECT DISTINCT column_name FROM table_name;
Practical Example
SELECT DISTINCT home_town FROM students;
-- Returns only distinct home towns (e.g., Jaipur, Delhi)
DISTINCT on Multiple Columns
When used on multiple columns, DISTINCT returns unique combinations of those columns, not each column independently:
SELECT DISTINCT home_town, gender FROM students;
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Key Takeaway
Use DISTINCT for readability and SQL-standard compliance. You may still see UNIQUE in legacy Oracle systems. For more SQL best practices, visit .
sql select distinct multiple columns
difference between unique and distinct in sql
select unique postgres
distinct vs unique meaning
select unique mysql
sql select distinct example
sql distinct w3schools
select distinct on one column