August 8th, 2008

DISTINCT Values

Posted by admin in C. SELECT Statement

> The DISTINCT option eliminates all duplicate column values for the column names following the word DISTINCT.
> Several columns can be considered for the DISTINCT operator.
> If the DISTINCT clause contains multiple columns, each unique combination of these columns is returned.

> DISTINCT is used in the SELECT clause. UNIQUE is used in the table definition.
> The DISTINCT predicate is similar to the UNIQUE predicate, except in the way that it treats a null value.
> If all non-null values in a result table are DISTINCT, then they are also UNIQUE.
> Multiple null values are not considered DISTINCT from each other, but they are considered to be UNIQUE. See UNIQUE.

SELECT DISTINCT column1, column2, ...
  FROM          table1, table2, ...;

> If a query includes the primary key of a table in its SELECT clause, then every row of the query result table will be unique, because the primary key has a different value in each row.
> If the primary key is not included in the query, duplicate rows can occur.
> In Microsoft Access, DISTINCT can not be used inside a column function parameter.
> In MySQL, DISTINCT can be used inside a COUNT column function, but not inside a SUM or AVG.

Comments are closed.

Sorry, the comment form is closed at this time.