Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Query

Re: Query

From: Billy Verreynne <vslabs_at_onwe.co.za>
Date: Mon, 11 Mar 2002 12:14:19 GMT
Message-ID: <3c8c9e50.271988717@news.saix.net>


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).

--
Billy
Received on Mon Mar 11 2002 - 06:14:19 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US