Databases Reference
In-Depth Information
Duplicate Removal
The DISTINCT keyword removes all duplicate rows from the results of a query.
For example, what if you wanted to see the department numbers for the employ-
ees in the EMP table? Your query might be something like this:
select deptno from emp;
DEPTNO
----------
20
30
30
20
30
30
10
20
10
30
20
30
20
10
14 rows selected.
But what you probably want is one row for each of the departments found in
the EMP table. In this case, use the DISTINCT keyword:
select distinct deptno from emp;
DEPTNO
----------
10
20
30
3 rows selected.
That's much easier to read. You now know that all of the employees belong
to one of three departments. However, there may be many other departments,
which would be listed in the department (DEPT) table. Some departments may
not have any employees right now. In Chapter 5, “Using Multiple Tables,” you'll
learn how to execute queries on joined tables to get this kind of information.
Search WWH ::




Custom Search