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

ID Title Price Description
1 Learn SQL 20 Learn SQL language
2 Learn MySQL 22 Learn MySQL language
3 HTML book 17 Learn HTML
4 Learn PHP 20 Introduction to PHP
5 Learn PHP 20 PHP course
SELECT DISTINCT price FROM coder_books;

Result

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

Result

Price Title
17 HTML book
20 Learn PHP
20 Learn SQL
22 Learn MySQL