SQL Distinct

SQL Distinct

The SQL DISTINCT is used to eliminate duplicate records and returns unique values.

Distinct syntax

-- select distinct column records from table
SELECT DISTINCT column_name FROM table_name

-- select specific columns 
SELECT DISTINCT column_name1, column_name2 FROM table_name

Distinct example

Coder books table

IDTitlePriceDescription
1Learn SQL20Learn SQL language
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML
4Learn PHP20Introduction to PHP
5Learn PHP20PHP course
SELECT DISTINCT price FROM coder_books;

Result

Price
17
20
22
SELECT DISTINCT price, title FROM coder_books;

Result

PriceTitle
17HTML book
20Learn PHP
20Learn SQL
22Learn MySQL