Categories
SQL Server Step By Step

SQL Distinct

SQL Distinct

Hi friends, in this post we will learn about SQL Distinct. Distinct keyword is used to get distinct (different) values. SQL DISTINCT keyword is used in with SELECT statement, it eliminate all the duplicate records and fetching only unique records.

Earlier we had discussed about SQL Group by Clause,SQL Order By Clause,SQL Select Top ClauseLike Clause SQL ServerSQL AND & OR OperatorsSQL Where Clause, Delete Query SQL Server, SQL Update Statement, SQL Select Statement, SQL Insert Statement, Drop Table SQL Server, Rename Table in SQL Server, Create Table SQL Server, Schema In SQL Server, SQL Server Operators, Data Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.

Table Structure :

ID NAME AGE ADDRESS SALARY
1 MANN 30 GURGAON 20000
2 JAI 21 Delhi 15000
3 AMAN 33 Kota 12000
4 AMIT 25 Mumbai 6000
5 SURESH 37 Bhopal 8000
6 Komal 22 GURGAON 4000
7 MANN 31 DELHI 22000

SQL Server Distinct Query:

In below queries, query with DISTINCT gives you only 5 records, as it eliminate duplicate records, while second query gives you 7 records. 

----SELECT DATABASE----
USE HIGHTECHNOLOGY
GO
----DISTINCT EXAMPLES----
SELECT DISTINCT ADDRESS FROM EMPLOYEE 
GO
----ALL RECORDS----
SELECT ADDRESS FROM EMPLOYEE
GO

SQL Distinct