InterBase Quick Start: Part IV - Removing Duplicate Rows with DISTINCT
Columns often contain duplicate entries. The
DISTINCT keyword allows you to remove duplicate values from the result. It enables you to retrieve only distinct (different) values.
- If you want to retrieve all the job codes from the
JobTable, you can do that using the following query:
SELECT job_code FROM Job
As you can see, the result of this query contains many values, some of them duplicates. To remove duplicate values from the result, you have to use the
- Modify the previous query to include the
SELECT DISTINCT job_code FROM Job
This produces the desired result, each job code is listed only once.
- Now enter a query that specifies two columns using the
SELECT DISTINCT job_code, job_grade FROM Job
DISTINCTapplies to all columns thay you specify in a
SELECTstatement. In this case, the result shows duplicate job codes. That is because
job_gradetogether, so the combination of values in the result is distinct (no duplicates). You can see the expected result of this query in the image below: