T-SQL Distinct keyword
In T-SQL, the DISTINCT keyword is used with the SELECT statement to eliminate duplicate records and give only the unique documents.
Below is the situation where we have many duplicate records in the table. When we fetch records, it makes more sense to bring only unique documents in place of duplicates.
The syntax of the DISTINCT keyword is given below:
EMPLOYEES TABLE is given below:
Let us see how the SELECT query returns duplicate salary records.
This command produces the below output where the salary 4400 comes twice, which is a duplicate record from the real table.
Let us use the DISTINCT keyword with the above SELECT query and then see the result.
The command produces the below output, where we have not any duplicate entry.