Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Query
oracleinform_at_yahoo.com (Gopal) wrote:
> How to use distinct on 2 columns . For eg I have a table A with 2
>columns
>
>A B
>
>1 Oracle
>1 Oracle
>2 ORACLE
>
>In the above example first 2 records 2 columns are equal hence I want
>only 1 record out of the 2 records , How to imply distinct on such
>records , not using the rowid .
SELECT
DISTINCT a,b
FROM foobar
A B
------- -----------
1 Oracle 2 ORACLE
2 row(s) selected.
Distinct means that any duplicate _ROWS_ from the data set are represented as a single row.
Distinct does not refer to any specific column only - it refers to the complete row. Said row can contain one or more columns. Whatever you have specified as the projection of that SELECT statement.
You can do the same thing with a GROUP BY clause, e.g.
SELECT
a, b
FROM foobar
GROUP BY a,b
If you add COUNT(*) to the projection, you will get the individual row counts for each grouping (distinct row).
-- BillyReceived on Mon Mar 11 2002 - 06:14:19 CST
![]() |
![]() |