Contents Index Computing values in the SELECT list The FROM clause: specifying tables

ASA SQL User's Guide
  Queries: Selecting Data from a Table
    The SELECT list: specifying columns

Eliminating duplicate query results


The optional DISTINCT keyword eliminates duplicate rows from the results of a SELECT statement.

If you do not specify DISTINCT, you get all rows, including duplicates. Optionally, you can specify ALL before the select list to get all rows. For compatibility with other implementations of SQL, Adaptive Server syntax allows the use of ALL to explicitly ask for all rows. ALL is the default.

For example, if you search for all the cities in the contact table without DISTINCT, you get 60 rows:

SELECT city
FROM contact

You can eliminate the duplicate entries using DISTINCT. The following query returns only 16 rows.:

SELECT DISTINCT city
FROM contact
NULL values are not distinct 

The DISTINCT keyword treats NULL values as duplicates of each other. In other words, when DISTINCT is included in a SELECT statement, only one NULL is returned in the results, no matter how many NULL values are encountered.


Contents Index Computing values in the SELECT list The FROM clause: specifying tables