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 DISTINCT alternate

RE: SQL DISTINCT alternate

From: Toepke, Kevin M <ktoepke_at_cms.cendant.com>
Date: Wed, 20 Jun 2001 11:29:19 -0700
Message-ID: <F001.00330AEE.20010620113234@fatcity.com>

As I see it, there are several questions here:

1)      Can I use DISTINCT to do a sort?
        Yes and no. In Oracle 7, a DISTINCT does an implicit sort
        In Oracle 8, it does a "SORT NOSORT" operation. Dupicates are
removed but the output is NOT guaranteed to be in sorted order.
2)      How do I sort the output?
        Use the "ORDER BY" clause as in:
                SELECT a, b, c FROM tab_1 ORDER BY a, b, c
3)      How do I get around the performance hit of a SORT operation?
        In Oracle 8.0 through 8.1.6 (fixed in 9i and 8.1.7) there is a bug
that causes the optimizer to choose a horrendous execution path if you are ordering by a column that is referenced in the WHERE clause.
        Workaround From:
                SELECT a, b, c FROM tab_1 WHERE a > 33 ORDER BY a, b, c:
        to:
                SELECT /*+ NO_MERGE(d) */ a, b, c FROM (
                        SELECT a, b, c FROM tab_1 WHERE a > 33
                ) ORDRE BY a, b, c;

Kevin

-----Original Message-----

Sent: Wednesday, June 20, 2001 1:50 PM
To: Multiple recipients of list ORACLE-L

Hi
In a sql stmt what will be the impact if we used DISTINCT clause and how we can overcomes on the performance bottleneck caused by DISTINCT. like ... SELECT DISTINCT A,B,C FROM TAB_1 I want to get same output without using distinct?Is this possible?If, YES then how?
Thanks in advance
-Seema



Get your FREE download of MSN Explorer at http://explorer.msn.com

--

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

Author: Seema Singh
  INET: oracledbam_at_hotmail.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists

--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--

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

Author: Toepke, Kevin M
  INET: ktoepke_at_cms.cendant.com
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists

--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Wed Jun 20 2001 - 13:29:19 CDT

Original text of this message

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