Javatpoint Logo
Javatpoint Logo

SQL Server DISTINCT Clause

In SQL Server, DISTINCT clause is used to remove duplicates from the table. The DISTICT clause is only used with SELECT statement.

Syntax:

Parameter explanation

expressions: It specifies the columns or calculations that you want to retrieve.

database_name & table_name: It specifies the name of the database and name of the table on which you want to do your operations.

Example:

DISTINCT clause with single expression

You have a table named "Employees", having the following data:

SQL Distinct clause 1

Select distinct salary from Employees where salary is greater than 12000.

Output:

SQL Distinct clause 2

Here, you can see that there is only 6 distinct salaries within 9 records. Distinct clause shows only unique records.


DISTINCT clause with multiple expressions

DISTINCT clause can also be used with multiple expressions. It will remove duplicates from more than one field in your SELECT statement.

Output:

SQL Distinct clause 3
Next TopicGroup By Clause




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA