Excluding duplicate rows from the result table of a query

You can ask Db2 to exclude multiple identical rows from a query result table. For example, a query might return multiple rows for each employee when one row per employee is sufficient for your program.

Procedure

Specify the DISTINCT keyword in the query.

The DISTINCT keyword excludes duplicate rows from your query result table, so that each row contains unique data.

Restriction: You cannot use the DISTINCT keyword with LOB columns or XML columns.

Example

The following SELECT statement lists unique department numbers for administrative departments:
SELECT DISTINCT ADMRDEPT
  FROM DSN8D10.DEPT;
The result table looks similar to the following output:
ADMRDEPT
========
A00
D01
E01