DISTINCT and ALL arguments

DISTINCT Definition


DISTINCT argument in a SELECT query specifies that only distinct rows of data can be returned.

ALL Definition


ALL argument in a SELECT query specifies that all rows of data, duplicate rows included, can be returned (default behaviour).

DISTINCT and ALL Usage


To return distinct values:

SELECT DISTINCT column1, column2,... FROM table_name

To return all values:

SELECT ALL column1, column2,... FROM table_name

Since ALL argument is the default behaviour, the above query and

SELECT column1, column2,... FROM table_name
have the same effect.

DISTINCT and ALL Examples

For our examples, we will use a student table.

To show all values of a first name column:

SELECT ALL FirstName FROM Student /* same as: SELECT FirstName FROM Student */
show all values

To show only unique values:

SELECT DISTINCT FirstName FROM Student
show only unique values

See also