Group By .. Order Results in Oracle 8i

Oracle 9i (9.2) makes statement that 'Group by does not guarantee order of results .. use Order by to sort results'.
Does this mean that under prior releases, esp. 8.1.7, that 'Group by' provides the proper Sort order of the results?
Or is 9.2 documentation, just clarifying what has always been the case?

Here is some information from the 8.1.7 SQL reference.
Use the order_by_clause to order rows returned by the statement. Without an order_by_clause, no guarantee exists that the same query executed more than once will retrieve rows in the same order.

Similar Messages

  • Problem with group by/order by clause when using huge data

    Hi,
    I'm using below query on my table of size more than 210 million rows.
    SELECT booking_date FROM T_UTR
    WHERE four_eyes_status = 'A' AND booking_date <= '01-jul-2005' AND booking_date >= '01-jan-2004'
    AND invoice_id IS NULL AND link_id = 12345
    AND billing_indicator = 'L'
    GROUP BY booking_date ORDER BY booking_date
    If I'm skipping last line "GROUP BY booking_date ORDER BY booking_date", its giving me immediate result, but, because of group by/order by, the query may take 30 seconds to 2 minutes based on the data fetched for the date range. It may vary from 2 to 2 million rows, & grouping by for so many rows at run time will automatically take some time.
    Here I want to know, is there any procedure in oracle(any function based index) so that I can store/retrieve distinct values for link_id, & booking_date without grouping them at run time. Or the performance of the query can be increased
    Thanks
    Deepak

    Hi,
    You can use Materialized Views as stated earlier - specifically by using Query Rewrite. If the conditions on columns "four_eyes_status", "invoice_id", and "billing_indicator" never change in your query - then you can create a Materialized View that is targeted for those conditions and has lower cardinality (since you aren't grouping by those columns). The "COUNT(*)" allows the use of the DISTINCT operator in addition to "GROUP BY' as well for Query Rewrite.
    Create the Materialized View like this:
    CREATE MATERIALIZED VIEW test_mv1
    BUILD IMMEDIATE
    USING NO INDEX
    REFRESH FORCE ON DEMAND
    ENABLE QUERY REWRITE
    AS
    SELECT booking_date
         , link_id
         , COUNT(*) AS count_star
    FROM T_UTR
    WHERE four_eyes_status = 'A'
      AND invoice_id IS NULL
      AND billing_indicator = 'L'
    GROUP BY booking_date
           , link_id ;To improve performance further - create an index on the "LINK_ID" column like this:
    CREATE INDEX test_mv1_link_id_idx
    ON test_mv1 (link_id);Then - gather stats immediately on the Materialized View so that the CBO can use it for rewriting your original query - like this:
    BEGIN
       DBMS_STATS.gather_table_stats (ownname               => USER
                                    , tabname               => 'TEST_MV1'
                                    , partname              => NULL
                                    , estimate_percent      => DBMS_STATS.auto_sample_size
                                    , block_sample          => FALSE
                                    , method_opt            => 'FOR ALL COLUMNS SIZE 1'
                                    , degree                => NULL
                                    , granularity           => 'ALL'
                                    , cascade               => TRUE
                                    , no_invalidate         => FALSE
    END;
    /Now - the CBO should be able to rewrite your original query to use the Materialized View - provided you set up your session for Query Rewrite like this:
    ALTER SESSION SET query_rewrite_enabled = TRUE;
    ALTER SESSION SET query_rewrite_integrity = ENFORCED; -- set this to whatever staleness you can tolerate - see the docs for details...Now - after setting up your session - try running your query with autotrace to see if it was rewritten...
    Good luck!
    Message was edited by:
    PDaddy

  • Getting first row in a group by order by sql

    Hi all,
    I'm having problems with the query below. What I want is to get a count of hotelid and group it then take the top result. My problem is that the version of oracle that I'm using is giving me errors because of the nested group by, order by. Is there any way around this?
    SELECT *
    FROM (SELECT agentid, hotelid, COUNT(hotelid) AS COUNT
    FROM akorders a, akworklist_summary b
    WHERE a.agentid = 1408946 AND
    a.akorderid = b.akorderid
    GROUP BY agentid, hotelid
    ORDER BY COUNT DESC)
    WHERE ROWNUM < 2
    TIA!
    Brian

    SELECT agentid, hotelid, COUNT(hotelid) AS COUNT
    FROM akorders a, akworklist_summary b
    WHERE a.agentid = 1408946 AND
    a.akorderid = b.akorderid
    GROUP BY agentid, hotelid
    HAVING COUNT(*) = (SELECT MAX(icount)
                       FROM (SELECT agentid, hotelid, COUNT(hotelid) AS icount
                             FROM akorders a, akworklist_summary b
                             WHERE a.agentid = 1408946 AND
                                   a.akorderid = b.akorderid
                                   GROUP BY agentid, hotelid ))

  • Sort Order problem in Oracle 11g

    Hi,
    While executing the below query in 10g and 11g, I got different results.
    SELECT loan.Ins_Id,
    ARev.revision,
    ADet.Acc_Id,
    loan.Loan_Id
    FROM
    Account_Det ADet
    join Acc_REV ARev
    on ADet.Acc_Id = ARev.Acc_Id
    join LoanAcc loan
    on loan.Loan_Id = ARev.Loan_Id
    join Interest_Det Ins
    on Ins.Ins_Id = loan.Ins_Id
    where Ins.Ins_Id in ('691','707')
    and ARev.revision=
    (select max(revision) from Acc_REV where Loan_Id =
    (select max(Loan_Id) from LoanAcc where Ins_Id =Ins.Ins_Id
    ) AND ADet.Acc_Id = '312'
    ORDER BY TO_NUMBER(ARev.revision) ASC;
    Result in Oracle 11g
    INS_ID  REVISION  Acc_ID   Loan_Id
    707      2      312    238
    691      1      312    234
    Result in Oracle 10g
    INS_ID  REVISION  Acc_ID   Loan_Id
    691      1      312    234
    707      2      312    238
    The order in both the cases were different.The order in 11g was not in ascending order.Though the data in both the databases
    is same. Could anyone please tell me why is this happening?. Is there any diffeence in the architecure of ORDER BY (sort) in
    10g and 11g. If I modify the above query by avoiding the subquery I get the correct result(i.e in ascending order).
    SELECT loan.Ins_Id,
    ADet.Acc_Id,
    loan.Loan_Id
    FROM
    Account_Det ADet
    join Acc_REV ARev
    on ADet.Acc_Id = ARev.Acc_Id
    join LoanAcc loan
    on loan.Loan_Id = ARev.Loan_Id
    join Interest_Det Ins
    on Ins.Ins_Id = loan.Ins_Id
    where Ins.Ins_Id in ('691','707')
    and ARev.revision in ('100','101')
    AND ADet.Acc_Id = '312'
    ORDER BY TO_NUMBER(ARev.revision) ASC;
    Edited by: KZON on Apr 7, 2011 4:46 AM

    Hi all,
    I have modified the query by giving To_Number(ARev.revision) before sub query. Now Oracle 11g returns results in ascending order. But 10g returns results in ascending order with out using To_Number()
    NOte:- Type of ARev.revision is VARCHAR
    SELECT loan.Ins_Id,
    ARev.revision,
    ADet.Acc_Id,
    loan.Loan_Id
    FROM
    Account_Det ADet
    join Acc_REV ARev
    on ADet.Acc_Id = ARev.Acc_Id
    join LoanAcc loan
    on loan.Loan_Id = ARev.Loan_Id
    join Interest_Det Ins
    on Ins.Ins_Id = loan.Ins_Id
    where Ins.Ins_Id in ('691','707')
    and To_Number(ARev.revision)=
    (select max(revision) from Acc_REV where Loan_Id =
    (select max(Loan_Id) from LoanAcc where Ins_Id =Ins.Ins_Id
    ) AND ADet.Acc_Id = '312'
    ORDER BY TO_NUMBER(ARev.revision) ASC;
    Result
    INS_ID  REVISION  Acc_ID   Loan_Id
    691      1      312    234
    707      2      312    238
    Is there any difference in ORDER BY clause in Oracle11g and 10g ?
    Edited by: KZON on Apr 7, 2011 4:45 AM

  • Patches 7446163 y 6851110 in order to use Oracle Text from UCM

    Hello, we have Oracle Enterprise Edition 11.2.0.1 on AIX 6.1.0.0 (64 bits). The client want to use Oracle Text from Universal Content Management, he told me about install the patches 7446163 y 6851110 in order to enable Oracle Text from UCM. I reviewed in Metalink but the readme said that those patches are for Oracle 11.1.0.7. That version (11.2.0.1) include already those patches or those are necessary for we can use the funcionality of Oracle Text from Universal Content Management? I reviewed the components installed on database and the Oracle Text is installed and active.
    Thanks for your help.
    Sincerely,
    Ruben Nieto
    DBA

    Hi
    Oracle DB usually would be installed with Oracle Text enabled (the db side) . To use the features for this we need to have OracleText component enabled on UCM which as you mentioned is already installed and enabled on the ucm server .
    If both the above conditions are already met then you would not need to install any further patches.
    Let me know if it is fine on db and ucm .
    Verify that Oracle Text is enabled on db by executing the following query :
    select comp_name, status from dba_registry;
    It should return the the following result : Oracle Text VALID
    To verify if the component for UCM is installed then you would need to check Administration - Configuration for <instance name> - Enabled Components
    Thanks
    Srinath
    Edited by: Srinath Menon on Dec 26, 2010 8:38 PM

  • What are the key fields used to group double orders in t-code SDD1?

    What are the key fields used to group double orders in t-code SDD1?
    Cheers,
    VT

    Hi,
    You can group the duplicate sales documents with the help of the following fields,
    Sold-To-Party,Document type,date and sales area details.
    Regards,
    Gopal.

  • Use Handling Units to group production orders?

    Hello,
    can I use Handling Units to group production orders together? We have a workcenter where all our orders go through and we'd like to group, say, the morning's orders in a single HU on which we could post a single transaction (batch?) instead of posting on each and every order.
    Thanks,
    Jonathan

    Please check OSS note 793168.

  • XK03 can be restricted by account group in order to prevent general users

    Hello Gurus,
    Please advise, if XK03 can be restricted by account group in order to prevent general user population from displaying employee data ?
    I understand that XK03 has auth object  F_LFA1_GRP for account group in which I restricted with 03 and particular account groups but still the test is failing because the test user is able to view employee data.
    Please suggest..
    Regard's
    Salman

    Hi Alex,
    Thank you !
    By your last update, do you mean auth group or account group? If you are talking about auth group then this auth object F_LFA1_BEK (XK03) has auth group.
    I checked the F_LFA1_GRP  is active in SU24. Is there something which i need to look in F_LFA1_BEK for particular auth group after restricting the auth object F_LFA1_GRP with account group ?
    Thank you for your valuable suggestions
    Regard's
    Salman

  • Query for Group by & order by

    Hi all,
    I have a table name as angdata77 having attributes like asigno..
    i want to retrieve data from angdata77 by using both group by & order by clauses.. for total count..
    am using the query as
    select asigno,count(*) from angdata77 group by asigno order by asigno;
    Is there any other query for retrieving the data from angdata77
    Thanks in Advance,
    Venkatesh J.

    885756 wrote:
    Ya it's good.. Performance also good while retrieving data...
    I want to know other Possibilities also sir...There will be no better alternative for this, because this is the most simple and straight forward way to get the output you are looking for..
    Go ahead without any confusion... :)

  • EA1 - SQL Formatter issues (JOINs and GROUPs and ORDER BY oh my ;)

    Great job with improving the SQL Formatter, but it still has some bugs that need to be worked out.
    The key words JOIN and it's modifiers INNER, LEFT, RIGHT and FULL OUTER are not recognized as master key words. As such they end up flush against the left margin Also when GROUP BY and/or ORDER BY key words are present in an outer most select statement the other key words are not indented far enough to be right aligned with the end of the word BY and are indented too far to be right aligned with the word GROUP or ORDER. In sub queries, GROUP and ORDER BY are correctly right aligned with their respective SELECT statements.

    We're picking up and collating the Formatter issues. I'll add these.
    Specific bug for these #7013462
    Sue

  • Would anyone please give me a test result of Oracle 9iFS

    We want to build a content management system. We've already built a MIS and the data stored in a Oracle database . The data in the content management will be used by the MIS . would anyone please give us a test result of Oracle 9iFS. We want know the capability, reliability of 9iFS . It will be appreciated If anyone can give us some proposes.
    thanks .

    Thanks for replying. i've tried doing it with one square as a
    movie clip symbol and then flipping that square over with the 3d
    rotation tool and then over and over. but i'm having to draw other
    squares on other layers to make up the rest of the square as it
    gets created. is this the right way to do it? what would be the
    simplest way? i know you said its just an animation, but how would
    you create the animation?
    Thanks

  • To add order mgmnt in oracle crm ondemand

    is it possible to add order management in oracle crm ondemand? if it's could u pl tell me the steps involved
    mailid: [email protected]
    Edited by: user9005557 on Jan 19, 2010 4:31 AM

    There are couples of web services provided by oracle for this purpose, by using that you can insert, update, query, delete records in CRM OnDemand.
    So you need to write the web service client program which takes data from your web form and create record in OnDemand. It can be in any language / platform (like java, c++, PHP etc)
    Check web services guide for more details.
    Dinesh

  • GROUP BY & ORDER BY  in a Report

    How to Implement GROUP BY & ORDER BY in a Report?

    Hi,
    Order by: It is possible to sort the char value according to the values (asc or desc) of an atribute of this char...is this what you were looking for?
    Group by: May be can be achieved by drilldwon sequence, with the grouping char to the left of the char values to be grouped...again, is this what you had in mind?

  • Order checking via Oracle Wireless

    Dear all;
    I was wondering is it possible to perform order checking thru Oracle 9i Wireless Application. I am currently in a project trying to develop a mobile application that can directly integrate with Oracle 11i E-Business Suite, eg: for order checking, inventory status, credit limit, etc.
    Please help. Would appreciate if u can direct me to where i cane get more technical information regarding this possibilities.
    thank;
    andrew, Malaysia

    Hi,
    Did you change the TNSNAMES.ORA file for DS? you have to add TNS entry to DS TNSNAMES.ORA file.
    Go to $DB_Default_Home$\netword\admin and open TNSNAMES.ORA file in notepad. Copy the tns entry from which you are connecting from SQL*plus.
    Go to $DS_Default_Home$\netword\admin and open TNSNAMES.ORA file in notepad. paste the tns entry you copied.
    Now try to connect from form builder.
    regards,
    Qasim Javaid

  • Prod Orders merge for oracle requirement

    Hi,
    Iu2019m a xi consultant. I need to know about Production Order processing.
    Iu2019ve to send sales orders (with multiple items) from oracle. And I need to get back the
    production orders back to oracle.
    Like:
    Sales order 1 header
    Sales order item1u2026
    Sales order item 2u2026
    Sales order 2 header
    Sales order item1u2026
    Sales order item 2u2026
    u2026.
    As per my understanding, for each sales order item, thereu2019ll be a production order in sap. If this is right, If I use Idoc LOIPRO, Iu2019ll get the individual production orders per every idoc. But I need to send the same way I get the data from Oracle.
    Like:
    Production order 1 header (with ref. to sales order 1 header)
    Production order item1u2026  (with ref. to sales order item 1 header)
    Production order item 2u2026 (with ref. to sales order item 2 header)
    Production order 2 header (with ref. to sales order 2 header)
    Production order item1u2026(with ref. to sales order item 1 header)
    Production order item 2u2026(with ref. to sales order item 2 header)
    u2026
    This is the requirement from customer side.
    Is it possible with standard Idoc LOIPRO?
    If yes, where I need to consolidate(merge) the individual IDocs to a single production order response to oracle?
    Is there any better approach?
    thanks
    zia

    Solved.

Maybe you are looking for

  • How to create a pie diagram and display it in html code

    hii frds, happy 2 meet u all. I want to know how to create a pie diagram that should not be devleloped by using applet, and use it in the html code to display a pie diagram in browser. ex code: package temp; import java.awt.*; import java.awt.image.B

  • How do I manually put camera raw 8.3 into APE11

    Ive tried the dng download but it did nothing in putting the new raw 8.3 into my Photoshop elements 11. How do I do it manually? I cant find anywhere to help. Ive just bought a Canon 70D and now cant read the raw files.

  • (RTF) Check if there is enogh space for tables on page...

    Hi All, I have a report consisting of various tables of grouped data, each of which can contain varying amounts of rows. The first row of each table is defined as the header row and set to repeat across page breaks. What is happening as a result, is

  • Load resource information before save

    We use dynamic tabbed user form to display user's multiple resource accounts. When we edit one resource account then save the change, validation error show up because other resource tabs have required field that are still blank. The reason for blank

  • How do I make a bootable copy of my iMac factory discs?

    Hello There, After reading all the horror stories about iMacs being in serious trouble if they don't have their original factory discs I would like to make bootable, working copies of mine in case the originals get damaged. I know you are supposed to