Back-End Development SQL basics

SQL Distinct


Where SQL select statement selects rows from a database, SQL Distinct is used with SELECT to select only distinct values (different).

Sql Select Distinct

In a table with duplicate entries, select distinct statement returns unique rows only.
Syntax:
SELECT DISTINCT column_name,column_name
FROM table_name;

Demo Database Table: Customers

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
144dcv4 Rahul 700912366 #001,sec-19 c chd
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
123eed3 Ramesh 987654321 #12,sec-4 mohali
144dcv4 Rahul 700912366 #001,sec-19 c chd

Query:
SELECT DISTINCT City FROM Customers;

RESULT:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd