Loading ...

What is distinct in SQL | CodeAsp.Net

DISTINCT In SQL

 /5
0 (0votes)

The SQL DISTINCT keyword specifies that only distinct / non-duplicate results are to be returned and used together with the SQL SELECT keyword.
We can apply DISTINCT on a single columns or to multiple columns.
Create Table users
(
FirstName varchar(50),
City varchar(50)
)
Insert into users (FirstName,City) values(null,'Noida')
Insert into users (FirstName,City) values('vijendra','Delhi')
Insert into users (FirstName,City) values('singh','Mumbai')
Insert into users (FirstName,City) values(null,'CallCutta')
Insert into users (FirstName,City) values('shakya','Hyderabad')
Insert into users (FirstName,City) values('vijendra',null)
Insert into users (FirstName,City) values('vijendra',null)

The SQL DISTINCT clause is used together with the SQL SELECT keyword, to return a dataset with unique entries for certain database table column.
Select Distinct FirstName from users
this Query gives following results
FirstName
Null
shakya
singh
vijendra

Distinct on the multiple column,In this Distinct returns the unique Values of both column values combination.
SELECT DISTINCT FIRSTNAME,CITY FROM users

this query gives following results:
FirstName          City
NULL                CallCutta
NULL                Noida
shakya              Hyderabad
singh               Mumbai
vijendra            NULL
vijendra            Delhi

Comments (no comments yet)

  • :*
  • :*
  • :
 *

Top Posts