SQL Distinct

      No Comments on 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.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
144dcv4Rahul700912366#001,sec-19 c chd
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
123eed3Ramesh987654321#12,sec-4 mohali
144dcv4Rahul700912366#001,sec-19 c chd

Query:
SELECT DISTINCT City FROM Customers;

RESULT:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd

Leave a Reply

Your email address will not be published. Required fields are marked *