Excluding Duplicate Rows

See Also

Some Select queries create result sets that contain duplicate rows. For example, the following query for an employee table displays the job code for each row in the table:

SELECT job_id 
FROM employee
ORDER BY job_id

Because more than one employee can have the same job, this query can create a result set similar to the following:

job_id

2
3
4
5
5
6
6
...

Note   The duplicate rows displayed by the query do not necessarily represent true duplicates in the input source for the query. Instead, they appear as duplicates in the result set because columns that would otherwise distinguish one row from another are not displayed.

If you want to see only unique values in a result set, you can specify that you want to exclude duplicates from the result set.

To exclude duplicate rows from the result set

  1. Ensure nothing is selected, then choose Property Pages from the View menu.

  2. In the Query tab of the Property pages window, select Distinct values.

    The Query Designer inserts the keyword DISTINCT in front of the list of display columns in the SQL statement.

    Note   Using the DISTINCT keyword in SQL Server results in a non-editable query.