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

Home -> Community -> Mailing Lists -> Oracle-L -> RE: SQL to retrieve all distinct records

RE: SQL to retrieve all distinct records

From: Cary Millsap <cary.millsap_at_hotsos.com>
Date: Thu, 15 Apr 2004 13:42:06 -0500
Message-ID: <004901c42319$5ce62e00$6901a8c0@CVMLAP02>


...as long as you don't mind that the row is selected at random.

Cary Millsap
Hotsos Enterprises, Ltd.
http://www.hotsos.com
* Nullius in verba *

Upcoming events:
- Performance Diagnosis 101: 5/7 Dallas, 5/18 New Jersey, 6/22 Pittsburgh

- SQL Optimization 101: 4/19 Denver, 5/3 Boston, 5/24 San Diego
- Hotsos Symposium 2005: March 6-10 Dallas
- Visit www.hotsos.com for schedule details...


-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Juan Cachito Reyes Pacheco
Sent: Thursday, April 15, 2004 12:28 PM
To: oracle-l_at_freelists.org
Subject: Re: SQL to retrieve all distinct records

I think your approach is right if you want to return one row from every discint a,b group.

I suppose select * from testing

Juan Carlos Reyes Pacheco
OCP
Database 9.2 Standard Edition
----- Original Message -----
From: "Alison Barak" <ambarak_at_hotmail.com> To: <oracle-l_at_freelists.org>
Sent: Thursday, April 15, 2004 11:23 AM
Subject: RE: SQL to retrieve all distinct records

I believe I have found a solution. Just wonder if anyone else has an alternative or better approach?

select * from testing where rowid in (select min(rowid) from testing group
by a,b);

thanks.

alison

>From: "Alison Barak" <ambarak_at_hotmail.com>
>To: oracle-l_at_freelists.org
>Subject: SQL to retrieve all distinct records
>Date: Thu, 15 Apr 2004 09:38:28 -0400
>
>Hi,
>can someone assist me with formulating a query to retrieve all distinct
>records. I need to retrieve all three columns a,b &c based on the
distinct
>of the two columns a & b.
>
>SQL> select * from testing;
>A B C
>---------- ---------- ----------
>APPS APPS R1
>SYS SYS2 R2
>SYS SYS2 R3
>DOC DOC2 R4
>DC DC2 R5
>DOC DOC R6
>
>The result should be
>A B C
>---------- ---------- ----------
>APPS APPS R1
>SYS SYS2 R2
>DOC DOC2 R4
>DC DC2 R5
>DOC DOC R6
>
>
>I tried using group by/having count but was not successful. Any idea?
>
>Thanks.
>
>alison
>



Persistent heartburn? Check out Digestive Health & Wellness for information
and advice. http://gerd.msn.com/default.asp

Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------


----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request_at_freelists.org
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request_at_freelists.org
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------
Received on Thu Apr 15 2004 - 15:16:10 CDT

Original text of this message

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