SQL : Select Query : Distint Clause
Introduction:
The DISTINCT clause allows you to remove duplicates from the result set. The DISTINCT clause can only be used with select statements.
The syntax for the DISTINCT clause is:
SELECT DISTINCT columnsFROM tablesWHERE predicates;
Example #1
Let's take a look at a very simple example.
SELECT DISTINCT categoryFROM ebooks;
This SQL statement would return all unique categories from the ebooks table.
Example #2
The DISTINCT clause can be used with more than one field.
For example:
SELECT DISTINCT category, publisherFROM ebooks;
This select statement would return each unique category and publisher combination. In this case, the distinct applies to each field listed after the DISTINCT keyword.
The DISTINCT clause allows you to remove duplicates from the result set. The DISTINCT clause can only be used with select statements.
The syntax for the DISTINCT clause is:
SELECT DISTINCT columnsFROM tablesWHERE predicates;
Example #1
Let's take a look at a very simple example.
SELECT DISTINCT categoryFROM ebooks;
This SQL statement would return all unique categories from the ebooks table.
Example #2
The DISTINCT clause can be used with more than one field.
For example:
SELECT DISTINCT category, publisherFROM ebooks;
This select statement would return each unique category and publisher combination. In this case, the distinct applies to each field listed after the DISTINCT keyword.
Comments
Post a Comment