DISTINCT

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > DDL & DML Statements >

DISTINCT

The DISTINCT keyword displays only the first row found of any duplicate values found. For example, using the following SELECT statement, you see that some of the data for the AMOUNT column repeats:

SELECT Amount FROM checks

 

Result:

AMOUNT

---------

150

245.34

200.32

98

150

25

25.1

Notice that seven rows are selected and the amount 150 is repeated. What if you wanted to see how may different amounts were in this column? Instead, try this:

SELECT DISTINCT Amount FROM checks;

Result:

AMOUNT

---------

25

25.1

98

150

200.32

245.34

Notice that only six rows are selected. Because you specified DISTINCT, only one instance of the duplicated data is shown, which means that one less row is returned.

Examples:

 /* Example with distinct */

SELECT DISTINCT AuthorID FROM FilesAut ORDER BY AuthorID

 

/* Example with distinct in an aggregate. This example

counts only the pricelist field that have different values. */

SELECT COUNT(DISTINCT pricelist) FROM sales;

FROM

Identifies which table(s) to use in the SELECT statement.

Table name followed by an alias is supported.

JOINS in the FROM clause are supported.

Examples:

 

/* Extract all fields from a single table */

SELECT * FROM Customer

 

/* Extract selected fields from a single table */

SELECT First, Last, City, State FROM Customer

 

/* Extracts selected fields from two tables */

SELECT o.OrderedOn, o.Name, O.PartNum, p.PartNum, p.Description

FROM orders o, part p