Can we rewrite this query??

what i am i doing wrong here..
this query has performance issue.. RBE_SMF_ATTRIB_HISTORY table has 2 M records..
SELECT h.pricing_security_id,h.level1 mac1,
h.level3 mac3,h.level5 mac5,
h.mat_date maturity,h.country_of_issue country,h.px_date
FROM GPS.RBE_SMF_ATTRIB_HISTORY h
WHERE h.px_type = 'PS1'
AND (create_timestamp, pricing_security_id)
IN (SELECT MAX(smf.create_timestamp), smf.pricing_security_id
FROM GPS.RBE_SMF_ATTRIB_HISTORY smf,
GPS.WK_HOLDINGS_PORTFOLIO wkhp
WHERE smf.px_type = 'PS1'
AND smf.px_date = h.px_date
AND wkhp.pricing_security_id=smf.pricing_security_id
GROUP BY smf.pricing_security_id )

  SELECT h.pricing_security_id,h.level1 mac1,
         h.level3 mac3,h.level5 mac5,
         h.mat_date maturity,h.country_of_issue country,h.px_date
    FROM GPS.RBE_SMF_ATTRIB_HISTORY h
   WHERE h.px_type = 'PS1'
     AND (create_timestamp, pricing_security_id, px_date) IN (SELECT MAX(smf.create_timestamp), smf.pricing_security_id, smf.px_date
                                                                FROM GPS.RBE_SMF_ATTRIB_HISTORY smf,
                                                                     GPS.WK_HOLDINGS_PORTFOLIO wkhp
                                                               WHERE smf.px_type = 'PS1'
                                                              -- AND smf.px_date = h.px_date                                   <-- try commenting out this line
                                                                 AND wkhp.pricing_security_id = smf.pricing_security_id
                                                              GROUP BY smf.pricing_security_id, smf.px_date )
also do you have indexes on your pricing_security_id columns for table GPS.RBE_SMF_ATTRIB_HISTORY and GPS.WK_HOLDINGS_PORTFOLIO?
note: untested

Similar Messages

  • How can we rewrite this query for better performance

    Hi All,
    The below query is taking more time to run. Any ideas how to improve the performance by rewriting the query using NOT EXITS or any other way...
    Help Appreciated.
    /* Formatted on 2012/04/25 18:00 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    and vendor_id NOT IN ( /* Formatted on 2012/04/25 18:25 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    Thanks

    Try this one :
    This will help you for partial fetching of data
    SELECT /*+ first_rows(50) no_cpu_costing */
    vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    AND vendor_id NOT IN (
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    overall your query is also fine, because, the in this query the subquery always contain less data compare to main query.

  • How to rewrite this query

    How can i rewrite this query so it uses less inner joins (it causes my temp space to explode :) )
    ( SELECT Waardes.*, Tellers.Nr_Dataitems, Tellers.Nr_Details FROM
    ( SELECT extractvalue(Value(el_node), 'Node/Id') node,
    extractvalue(Value(el_dataitem), 'Detail/Title') Node_Title,
    extractvalue(Value(el_dataitem), 'Detail/Value') Node_Value
    FROM PHILIPS_XML x,
    TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
    TABLE (xmlsequence (extract (value(el_node),
    'Node/DataItems/DataItem/DetailSet/Detail'))) el_dataitem
    ) Waardes
    INNER JOIN
    SELECT A.Node, A.Nr_Dataitems, B.Nr_details FROM
    SELECT extractvalue(Value(el_node), 'Node/Id') node,
    count(extract(Value(aaa), 'DataItem')) Nr_Dataitems
    FROM PHILIPS_XML x,
    TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
    TABLE (xmlsequence (extract (value(el_node),
    'Node/DataItems/DataItem'))) aaa
    GROUP BY extractvalue(Value(el_node), 'Node/Id')
    ) A
    INNER JOIN
    SELECT extractvalue(Value(el_node), 'Node/Id') node,
    count(extract(Value(bbb), 'Detail')) Nr_details
    FROM PHILIPS_XML x,
    TABLE (xmlsequence (extract (value(x), '/Tree/Node'))) el_node,
    TABLE (xmlsequence (extract (value(el_node),
    'Node/DataItems/DataItem'))) aaa,
    TABLE (xmlsequence (extract (value(aaa),
    'DataItem/DetailSet/Detail' ))) bbb
    GROUP BY extractvalue(Value(el_node), 'Node/Id')
    ) B
    on A.node = B.NODE
    ) Tellers
    ON Waardes.NODE = Tellers.NODE )

    1st Make sure all paths are absolute (start with '/', not just the node name).
    Which release are you using.. Is the document based on an XMLSchema, if so, what annotations were used when registered the XML Schema ?. What does the explain plan look like...

  • Rewrite this query

    Hi all,
    Can we rewrite this query as simplest.Becasue when i Execute this query it will take more time appro 3hrs.So can we rewrite this as possible.
    SELECT  scon.uabscon_number,
                        scon.uabscon_cust_code,
                        scon.uabscon_prem_code,
                        scon.uabscon_mf_status,
                        letd.usrletd_mf_next_visit_date,
                        evau.ucrevau_invn_code,
                        evau.ucrevau_prod_number
                 FROM   uimsmgr.usrletd letd,
                        uimsmgr.ucrevau evau,
                        uimsmgr.uabscon scon
                 WHERE  scon.uabscon_mf_status = :cMoveForwardPhase
                 AND    scon.uabscon_status_ind IN ('A','R')
                 AND    evau.ucrevau_scon_number = scon.uabscon_number
                 AND    evau.ucrevau_event_type  = :currentLetterTypeLevel /* FLT1,ALT1,FLT2, ... */
                 AND    evau.ucrevau_value_1     = :letterTypeCode /* FV1,ASV1, ... */
                 AND    evau.ucrevau_activity_date = (SELECT max(ee.ucrevau_activity_date)
                                                      FROM   uimsmgr.ucrevau ee
                                                      WHERE  ee.ucrevau_scon_number = scon.uabscon_number
                                                      AND    (ee.ucrevau_event_type like 'FLT%'
                                                              OR ee.ucrevau_event_type like 'ALT%'))
                 AND   letd.usrletd_actual_cust_code  = scon.uabscon_cust_code
                 AND   letd.usrletd_prem_code         = scon.uabscon_prem_code
                 AND   letd.usrletd_letr_code         = :letterTypeCode /* FV1,ASV1, ... */
                 AND   letd.usrletd_printed_date      <= SYSDATE - :mfFirstDelayDays
                 AND   letd.usrletd_printed_ind       = 'Y'
                 AND   TRUNC(letd.usrletd_activity_date) >= TRUNC(evau.ucrevau_activity_date)
                 AND EXISTS (   SELECT 1
                                FROM   uimsmgr.utvsrvc srvc,
                                       uimsmgr.ucrserv serv
                                WHERE  serv.ucrserv_scon_number = scon.uabscon_number
                                AND    serv.ucrserv_cust_code   = scon.uabscon_cust_code
                                AND    serv.ucrserv_prem_code   = scon.uabscon_prem_code
                                AND    TRUNC(serv.ucrserv_next_visit_date) <= TRUNC(SYSDATE) + :mfDueRange
                                AND    serv.ucrserv_srvc_code   = srvc.utvsrvc_code
                                AND    srvc.utvsrvc_bus_sector_id = 1 /* only business sector 1*/
                                AND    DECODE( NVL(serv.ucrserv_next_visit_type, 'A'),
                                                   'NOFV', 'A',
                                                   'FV'  , 'F',
                                                   'FAS' , 'A',
                                                   'A'   , 'A',
                                                           'Z' ) = :visitType
                                );

    SELECT /*+ ordered */  scon.uabscon_number,
                        scon.uabscon_cust_code,
                        scon.uabscon_prem_code,
                        scon.uabscon_mf_status,
                        letd.usrletd_mf_next_visit_date,
                        evau.ucrevau_invn_code,
                        evau.ucrevau_prod_number
                 FROM   uimsmgr.usrletd letd,
                        uimsmgr.ucrevau evau,
                        uimsmgr.uabscon scon
                 WHERE   letd.usrletd_printed_date      <= SYSDATE - :mfFirstDelayDays and scon.uabscon_mf_status = :cMoveForwardPhase
                 AND    scon.uabscon_status_ind IN ('A','R')
                 AND    evau.ucrevau_scon_number = scon.uabscon_number
                 AND    evau.ucrevau_event_type  = :currentLetterTypeLevel /* FLT1,ALT1,FLT2, ... */
                 AND    evau.ucrevau_value_1     = :letterTypeCode /* FV1,ASV1, ... */
                 AND    evau.ucrevau_activity_date = (SELECT max(ee.ucrevau_activity_date)
                                                      FROM   uimsmgr.ucrevau ee
                                                      WHERE  ee.ucrevau_scon_number = scon.uabscon_number
                                                      AND    (ee.ucrevau_event_type like 'FLT%'
                                                              OR ee.ucrevau_event_type like 'ALT%'))
                 AND   letd.usrletd_actual_cust_code  = scon.uabscon_cust_code
                 AND   letd.usrletd_prem_code         = scon.uabscon_prem_code
                 AND   letd.usrletd_letr_code         = :letterTypeCode /* FV1,ASV1, ... */
                 AND   letd.usrletd_printed_ind       = 'Y'
                 AND   TRUNC(letd.usrletd_activity_date) >= TRUNC(evau.ucrevau_activity_date)
                 AND EXISTS (   SELECT 1
                                FROM   uimsmgr.utvsrvc srvc,
                                       uimsmgr.ucrserv serv
                                WHERE  serv.ucrserv_scon_number = scon.uabscon_number
                                AND    serv.ucrserv_cust_code   = scon.uabscon_cust_code
                                AND    serv.ucrserv_prem_code   = scon.uabscon_prem_code
                                AND    TRUNC(serv.ucrserv_next_visit_date) <= TRUNC(SYSDATE) + :mfDueRange
                                AND    serv.ucrserv_srvc_code   = srvc.utvsrvc_code
                                AND    srvc.utvsrvc_bus_sector_id = 1 /* only business sector 1*/
                                AND    DECODE( NVL(serv.ucrserv_next_visit_type, 'A'),
                                                   'NOFV', 'A',
                                                   'FV'  , 'F',
                                                   'FAS' , 'A',
                                                   'A'   , 'A',
                                                           'Z' ) = :visitType
                                )I suggest this admitting on letd.usrletd_printed_date.
    And it would be good if you would also have a lower limit for letd.usrletd_printed_date, so that you would have letd.usrletd_printed_date between ...

  • How can I rewrite this update stmt to improve its poor performance?

    Hi,
    I have the following update stmt that runs for over 6 hours. Here is the SQL and its plan:
                UPDATE TABLE1
                     SET mainveh = 'Y'
                 WHERE (comp#,polnum,a8dtef,a8deef,a8dtac,
                        DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                    IN (SELECT comp#,polnum,a8dtef,a8deef,a8dtac,
                               MAX(DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                          FROM TABLE1
                         GROUP BY comp#,polnum,a8dtef,a8deef,a8dtac);
    PLAN_TABLE_OUTPUT
    | Id  | Operation             | Name     | Rows  | Bytes |TempSpc| Cost (%CPU)|
    |   0 | UPDATE STATEMENT      |          |     1 |   108 |       |   798K  (1)|
    |   1 |  UPDATE               | TABLE1   |       |       |       |            |
    |   2 |   HASH JOIN           |          |     1 |   108 |  1079M|   798K  (1)|
    |   3 |    TABLE ACCESS FULL  | TABLE1   |    21M|   834M|       |   224K  (1)|
    |   4 |    VIEW               | VW_NSO_1 |    21M|  1364M|       |   440K  (1)|
    |   5 |     SORT GROUP BY     |          |    21M|   794M|  2453M|   440K  (1)|
    |   6 |      TABLE ACCESS FULL| TABLE1   |    21M|   794M|       |   224K  (1)|I'm using Oracle 10.2.0.3. The TABLE1 table has 21 million rows. The update stmt will update about 15 million rows. How can I rewrite this update stmt so it'll perform better? There is a primary index on all the columns selected in the subquery. That is the only index on TABLE1.
    Thank you!
    Edited by: user6053424 on Jul 21, 2010 6:59 AM

    Hi,
    Thank you for your suggestions. There is an index on the columns in the group by, it is the PK index on TABLE1. I'm suspecting that due to the amount of data to update, the optimizer decided that full table scan is cheaper than index scan. I'm very interested in the GTT idea, but still need some help if I decide to create a GTT from the subquery, because if I just do this:
    create global temporary table table1_tmp
    on commit preserve rows
    as SELECT comp#,polnum,a8dtef,a8deef,a8dtac,
               MAX(DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
          FROM TABLE1
         GROUP BY comp#,polnum,a8dtef,a8deef,a8dtac;then the original update stmt still has the DECODE and such in it, I'm not sure how much benefit that'll do to us:
    UPDATE TABLE1
                     SET mainveh = 'Y'
                 WHERE (comp#,polnum,a8dtef,a8deef,a8dtac,
                        DECODE(everif,'Y',10000,0)+auunit*100+vrcdsq)
                    IN (SELECT comp#,polnum,a8dtef,a8deef,a8dtac,???
                          FROM TABLE1);Your input is greatly appreciated! Thanks!

  • How can i improve this query.

    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .

    952936 wrote:
    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .If you are a beginner try to learn the ANSI Syntax. This will help you a lot to write better queries.
    Your select would look like this in ANSI.
    select *
    from tableA A
    JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_function(a.key);The good thing here is that this separates the typical joining part of the select from the typical filter criteria.
    The other syntax very often let you forget one join. Just because there are so many tables and so many filters, that you just don't notice correctly anymore what was join and what not.
    If you notice that the number of column is not what you expect, you can easiely modify the query and compare the results.
    example A
    Remove View B from the query (temporarily comment it out).
    select *
    from tableA A
    --JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    example B
    You notice, that values from A are missing. Maybe because there is no matching key in ViewB? Then change the join to an outer join.
    select *
    from tableA A
    LEFT OUTER JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)(The outer keyword is optional, left join would be enough).

  • How to rewrite this query without sub query please help me

    Hello All Good Evening,
    Could you please help me with this query, how can i write this query without sub query, or how can write this query another ways
    please help me
    select planno, status1, count(*) Counts from
    select a.ValetNO PlanNo  ,
    case 
         when JoinCode in ('00', '01', '02') then 'Actcess'
         when JoinCode in ('20', '21', '22', '23','38', '39') then
         'Secured' else 'Other' end Status1 ---, COUNT (*)
       from  dbo.ppt a(NOLOCK)  left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO  = b.ValetNO
    --group by a.ValetNO
      a group by planno, status1
    order by 2
    Thank you in Advance
    Milan

    Whats your objective here? Sorry, am not able to understand the reason for this change. 
    Try the below:(Not tested)
    ;With cte
    As
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 ---, COUNT (*)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    select planno, status1, count(*) Counts from cte
    a group by planno, status1
    order by 2
    Even below:
    select a.ValetNO PlanNo ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end Status1 , COUNT (1)
    from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
    Group by a.ValetNO ,
    case
    when JoinCode in ('00', '01', '02') then 'Actcess'
    when JoinCode in ('20', '21', '22', '23','38', '39') then
    'Secured' else 'Other' end

  • Can anyone explain this query.?

    Can anyone explain this query.?
    select nvl(s.p_id,q.p_id),nvl(s.p_type,q.p_type),nvl(s.p_line,q.p_line),
    nvl(s.sales2004,0),nvl(s.sales2005,0),nvl(q.quota2004,0),nvl(q.quota2005,0)
    from sales s
    full outer join quota q on(s.p_id = q.p_id and s.p_type=q.p_type and s.p_line=q.p_line)

    from sales s full outer join quota qTable quota is outer joined to table sales , if there are no matching records in table quota then also the query retuns the sales record with null values for the corresponding quota record columns
    NVL() has been used to handle such cases

  • How can i rewrite this code into java?

    How can i rewrite this code into a java that has a return value?
    this code is written in vb6
    Private Function IsOdd(pintNumberIn) As Boolean
        If (pintNumberIn Mod 2) = 0 Then
            IsOdd = False
        Else
            IsOdd = True
        End If
    End Function   
    Private Sub cmdTryIt_Click()
              Dim intNumIn  As Integer
              Dim blnNumIsOdd     As Boolean
              intNumIn = Val(InputBox("Enter a number:", "IsOdd Test"))
              blnNumIsOdd = IsOdd(intNumIn)
              If blnNumIsOdd Then
           Print "The number that you entered is odd."
        Else
           Print "The number that you entered is not odd."
        End If
    End Sub

    873221 wrote:
    I'm sorry I'am New to Java.Are you new to communication? You don't have to know anything at all about Java to know that "I have an error," doesn't say anything useful.
    I'm just trying to get you to think about what your post actually says, and what others will take from it.
    what does this error mean? what code should i replace and add? thanks for all response
    C:\EvenOdd.java:31: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=true;
    ^
    C:\EvenOdd.java:35: isOdd(int) in EvenOdd cannot be applied to ()
    isOdd()=false;
    ^
    2 errors
    Telling you "what code to change it to" will not help you at all. You need to learn Java, read the error message, and think about what it says.
    It's telling you exactly what is wrong. At line 31 of EvenOdd.java, you're calling isOdd(), with no arguments, but the isOdd() method requires an int argument. If you stop ant think about it, that should make perfect sense. How can you ask "is it odd?" without specifying what "it" is?
    So what is this all about? Is this homework? You googled for even odd, found a solution in some other language, and now you're just trying to translate it to Java rather than actually learning Java well enough to simply write this trivial code yourself?

  • Can anyone tell me how can i optimize this query...

    Can anyone tell me how can i optimize this query ??? :
    Select Distinct eopersona.numident From rscompeten , rscompet , rscv , eopersona , rscurso , rseduca , rsexplab , rsinteres
    Where ( ( (LOWER (rscompeten.nombre LIKE '%caracas%') AND ( rscompeten.id = rscompet.idcompeten ) AND ( rscv.id = rscompet.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscurso.nombre) LIKE '%caracas%') AND ( rscv.id = rscurso.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscurso.lugar) LIKE '%caracas%') AND ( rscv.id = rscurso.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rseduca.univinst) LIKE '%caracas%)' AND ( rscv.id = rseduca.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rsexplab.nombempre) LIKE '%caracas%' AND ( rscv.id = rsexplab.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rsinteres.descrip) LIKE '%caracas%' AND ( rscv.id = rsinteres.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscv.cargoasp) LIKE '%caracas%' AND ( eopersona.id = rscv.idpersona ) )
    OR ( LOWER (eopersona.ciudad) LIKE '%caracas%' AND ( eopersona.id = rscv.idpersona )
    PLEASE IF YOU FIND SOMETHING WRONG.. PLEASE HELP ME.. this query takes me aproximatelly 10 minutes and the database is really small ( with only 200 records on each table )

    You are querying eight tables, however in any of your OR predicates you're only restricting 3 or 4 of those tables. That means that the remaining 4 or 5 tables are generating cartesian products. (n.b. the cartesian product of 5 tables with 200 rows each results in g 200^5 = 320,000,000,000 rows) Then you casually hide this behind "distinct".
    A simple restatement of your requirements looks like this:
    Select eopersona.numident
      From rscompeten,
           rscompet,
           rscv,
           eopersona
    Where LOWER (rscompeten.nombre) LIKE '%caracas%'
       AND rscompeten.id = rscompet.idcompeten
       AND rscv.id = rscompet.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    Select eopersona.numident
      From rscurso ,
           rscv,
           eopersona
    Where LOWER (rscurso.nombre) LIKE '%caracas%'
       AND rscv.id = rscurso.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    Select eopersona.numident
      From rscurso ,
           rscv,
           eopersona
    Where LOWER (rscurso.lugar) LIKE '%caracas%'
       AND rscv.id = rscurso.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    ...From there you can eliminate redundancies as desired, but I imagine that the above will perform admirably with the data volumes you describe.

  • Can I refactor this query to use an index more efficiently?

    I have a members table with fields such as id, last name, first name, address, join date, etc.
    I have a unique index defined on (last_name, join_date, id).
    This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
    SELECT members.*
            FROM members
            WHERE last_name = 'Smith'
            ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
    SELECT members.*
            FROM members
            WHERE last_name like 'S%'
            ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
    Last_Name:  JoinDate:
    Smith          2/5/2010
    Smuckers     1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
    So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?

    xaeryan wrote:
    I have a members table with fields such as id, last name, first name, address, join date, etc.
    I have a unique index defined on (last_name, join_date, id).
    This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
    SELECT members.*
    FROM members
    WHERE last_name = 'Smith'
    ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
    SELECT members.*
    FROM members
    WHERE last_name like 'S%'
    ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
    Last_Name:  JoinDate:
    Smith          2/5/2010
    Smuckers     1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
    So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?Come on. Index column order does matter. "LIKE 'x%'" actually is full table scan. The db engine accesses contiguous index entries and then uses the ROWID values in the index to retrieve the table rows.

  • I can't use this query on 10G, but can use on 9i

    I have ever used bellow query and no error
    SQL>select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    When I use on 10G, I can't query
    1* select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    SQL> /
    select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    ERROR at line 1:
    ORA-01799: a column may not be outer-joined to a subquery
    Help me,Please
    Why I can't use this on 10G?
    when i change = to in , i can use
    but i don't want to change
    help me for the reason

    I don't this gonna work on 9i either.
    Chang your query to
    select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid )
    Where
    rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)

  • Is there any way to rewrite this query?

    Is there room for improvement/rewrite for this query so that it performs well?
    select distinct shp_locn
      from shp_mstr
    where zone = to_char(:b3)
       and locn_class = 'r'
       and aisle = 'GX-08'
       and dock =  'KN'
       and locn_id not in (select locn_id from tmp_shp_out_dtl)
    order by shp_locn

    user659394 wrote:
    Alex,
    Stop your st_u_pi_d f_u_c__king sarcasm. There were lots of instances like the below thread
    where you bring your boring sarcasm to meaningful technical discussions.
    If you dont want to answer, just leave it..... you C__u__n__t
    Error for a SELECT COUNT ... in stored proc
    Alex was giving you perfectly valid assistance.
    Your post has now been reported to the moderators as it is completely offensive, unprofessional and unnecessary.

  • Can we make this query shorter....?

    hi there
    Can any body help me in reducing the number of lines in this query ! I am using union to concat 3 queries. Select fields in every query are same and in where condition also most of the joins are same in every query. but in where clause only two conditions are different. Can we make this 3 queries into one becoze entire select statement fields are same and most of the where conditions are same !
    Below is the query:
    SELECT
    au1.bu_id,
    au1.first_nam,
    au1.last_nam,
    c.id,
    c.first_nam_d,
    c.last_nam_d,
    c.birth_dte_d,
    c.ssn_num_d,
    se.id schd_event_id,
    seu.dsc,
    ssc.dsc,
    sea.access_typ,
    sea.ATTENDEE_TYP
    FROM
    CLIENT c,
    APP_USER au1,
    SCHD_STAT_CD ssc,
    schd_event_url seu,
    schd_evnt se,
    SCHD_evnt_stat ses,
    SCHD_EVNT_ATTENDEE sea,
    CLIENT_APPT ca
    WHERE
    c.id = ca.client_id_k AND
    au1.bu_id = se.APP_USER_BU_ID_PRIME_K AND
    ssc.code = ses.SCHD_STAT_CD_CODE_K AND
    seu.code = se.SCHD_EVNT_URL_CODE_K AND
    se.id = ses.SCHD_EVNT_ID_K AND
    se.id = sea.SCHD_EVNT_ID_K(+) AND
    se.id = ca.SCHD_EVNT_ID_K AND
    sea.ATTENDEE_TYP(+) = 'WORKER' AND
    ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
    UNION
    SELECT
    au1.bu_id,
    au1.first_nam,
    au1.last_nam,
    c.id,
    c.first_nam_d,
    c.last_nam_d,
    c.birth_dte_d,
    c.ssn_num_d,
    se.id schd_event_id,
    seu.dsc,
    ssc.dsc,
    FROM
    CLIENT c,
    APP_USER au1,
    SCHD_STAT_CD ssc,
    schd_event_url seu,
    schd_evnt se,
    SCHD_evnt_stat ses,
    SCHD_EVNT_ATTENDEE sea,
    CLIENT_APPT ca
    WHERE
    c.id = ca.client_id_k AND
    au1.bu_id = se.APP_USER_BU_ID_PRIME_K AND
    ssc.code = ses.SCHD_STAT_CD_CODE_K AND
    seu.code = se.SCHD_EVNT_URL_CODE_K AND
    se.id = ses.SCHD_EVNT_ID_K AND
    se.id = sea.SCHD_EVNT_ID_K AND
    se.id = ca.SCHD_EVNT_ID_K AND
    sea.ATTENDEE_TYP = 'ROLE' AND
    ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
    UNION
    SELECT
    au1.bu_id,
    au1.first_nam,
    au1.last_nam,
    c.id,
    c.first_nam_d,
    c.last_nam_d,
    c.birth_dte_d,
    c.ssn_num_d,
    se.id schd_event_id,
    seu.dsc,
    ssc.dsc,
    sea.access_typ,
    sea.ATTENDEE_TYP
    FROM
    CLIENT c,
    APP_USER au1,
    SCHD_STAT_CD ssc,
    schd_event_url seu,
    schd_evnt se,
    SCHD_evnt_stat ses,
    SCHD_EVNT_ATTENDEE sea,
    CLIENT_APPT ca
    WHERE
    c.id = ca.client_id_k AND
    au1.APP_ROLE_NAM_DESKTOP_K = sea.ATTENDEE_ID_K AND
    ssc.code = ses.SCHD_STAT_CD_CODE_K AND
    seu.code = se.SCHD_EVNT_URL_CODE_K AND
    se.id = ses.SCHD_EVNT_ID_K AND
    se.id = sea.SCHD_EVNT_ID_K AND
    se.id = ca.SCHD_EVNT_ID_K AND
    sea.ATTENDEE_TYP = 'ROLE' AND
    ses.create_ts = (select max(create_ts) FROM SCHD_evnt_stat ses1 WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
    Thanks in advance
    prasanth a.s.

    Hi,
    it is difficult to change this query without the possibility to test it in a worksheet. But try the following query.
    I think it should be the same result as your 3 queries.
    SELECT au1.bu_id,
         au1.first_nam,
         au1.last_nam,
         c.id,
         c.first_nam_d,
         c.last_nam_d,
         c.birth_dte_d,
         c.ssn_num_d,
         se.id schd_event_id,
         seu.dsc,ssc.dsc,
         decode(sea.access_typ,NULL,' ',sea.access_typ) AS sea.access_typ,
         decode(sea.ATTENDEE_TYP,NULL,' ',sea.ATTENDEE_TYP) AS sea.ATTENDEE_TYP
    FROM CLIENT c,
         APP_USER au1,
         SCHD_STAT_CD ssc,
         schd_event_url seu,
         schd_evnt se,
         SCHD_evnt_stat ses,
         SCHD_EVNT_ATTENDEE sea,
         CLIENT_APPT ca
    WHERE c.id = ca.client_id_k
    AND au1.bu_id = se.APP_USER_BU_ID_PRIME_K
    AND ssc.code = ses.SCHD_STAT_CD_CODE_K
    AND seu.code = se.SCHD_EVNT_URL_CODE_K
    AND se.id = ses.SCHD_EVNT_ID_K
    AND se.id = ca.SCHD_EVNT_ID_K
    AND ses.create_ts = (select max(create_ts)
    FROM SCHD_evnt_stat ses1
                             WHERE ses1.SCHD_EVNT_ID_K = ses.SCHD_EVNT_ID_K)
    AND
    (sea.ATTENDEE_TYP(+) = 'WORKER' AND se.id = sea.SCHD_EVNT_ID_K(+)) --clause of the 1st query
    OR
    (sea.ATTENDEE_TYP = 'ROLE' AND se.id = sea.SCHD_EVNT_ID_K)               --clause of the 2nd query
    OR
    (sea.ATTENDEE_TYP = 'ROLE' AND se.id = sea.SCHD_EVNT_ID_K AND au1.APP_ROLE_NAM_DESKTOP_K = sea.ATTENDEE_ID_K) --clause of the 3rd query
    );

  • Can't Export this query to Excel v1.5.4 5940

    All,
    I have this query that I can't export to excel.
    SELECT '01' ,
    '<$25',
    COUNT(*),
    SUM(salary)
    FROM HR.employees
    WHERE department_id = '30'
    AND salary < 6000
    Query returns results, just can't export to excel.. Tried giving the literals alternate column names ....no effect.
    Thanks,

    Hi Charles,
    This issue has been logged as a bug.
    I know that these export issues are been actively worked on at the moment for out next major release.
    There is a workaround outlined here, although it not a great solution it may get you out of a bind in this one case.
    Re: Export will not work - sample query pasted
    CREATE VIEW workaround AS
    SELECT '01' AS col1 ,
    '<$25' AS col2,
    COUNT(*) AS col3,
    SUM(salary) AS col4
    FROM HR.employees
    WHERE department_id = '30'
    AND salary < 6000 ;
    SELECT * FROM workaround; -- export this result.
    Regards,
    Dermot

Maybe you are looking for