Query by using Not Exists

Hi,
What would be the alternative for the below query by using not exists .
select cust_name from cust_info where cust_name not in( select distinct cust_name from cust_details where status = 'CURRENT')
Thanks

it gives you all possible alternatives and ways tooptimize the query
Is it? I've actually seen a couple tools that do that - Quest and Leccotech come to mind. they would actually rewrite a query hundreds, if not thousands, of different ways - using every hint, even ones that had no reason to be used (and using different hint combinations), using different join orders (with the ordered hint), rewriting subqueries to joins, to inline views, to scalar subqueries in the select list, etc, etc (possibly even giving the MINUS rewrite). but the tools had no way to know which rewrite was optimal, so it would then just execute each and every one, which could take several days (considering that some of the rewrites were terrible).
so yeah, I think I'll hold onto that tuning guide for just a while longer ;)

Similar Messages

  • ORA-29540: class oracle/xml/sql/query/OracleXMLStaticQuery does not exist

    I am getting below error when trying to generate xml. Browsing on google did not help me. I would appreciate if someone can provide the solution.
    SQL> select dbms_xmlquery.getxml('select * from dual', 2) from dual;
    ERROR:
    ORA-29540: class oracle/xml/sql/query/OracleXMLStaticQuery does not exist
    ORA-06512: at "SYS.DBMS_XMLQUERY", line 19
    ORA-06512: at "SYS.DBMS_XMLQUERY", line 271
    ORA-06512: at line 1

    Then it is probably not the case that you are affected by the issue described in Metalink document 185857.1, but if I were you I would check it anyway, since it might be the problem.

  • Error on running BEx Query: Variable does not exist or is incorrectly used

    Hi all,
    I have a characteristic in my query which I restrict using a variable with Mutliple Single values.
    When I run the query in the Analyzer or RSRT, I get the following error:
    "Variable does not exist or is incorrectly used"
    Please help me fix this error.
    Thanks and Regards,
    Srilakshmi B

    Hi,
    I have a characteristic in my query which I restrict using a variable with Mutliple Single values.
    When you define any Filter Values, BEx will ask you to select either Single Values or Variables or Value Ranges etc..
    If you want to select by Multiple single values, you should include all the values in the Restriction area.
    Please do not define any variables, unless the User wants to enter any thing. Look for any other variables which are not defined correctly..........
    Regards,
    Suman

  • Using NOT EXISTS to read from the same table.

    Hi,
    If I use the flwg SQL's:
    select * from outstanding_balance
    where dt_cats_date = '21,Nov 2005'
    order by id_entity,id_object_type,id_object,id_payment_control ASC
    select * from outstanding_balance
    where dt_cats_date = '18,Nov 2005'
    order by id_entity,id_object_type,id_object,id_payment_control ASC
    Rows returned by the 1st is 15363
    Rows retured  by thr 2nd Query id 15325
    ie difference of 38But,when I use the NOT EXISTS operator :
    select *
    from outstanding_balance ob1
    where ob1.dt_cats_date = '21 Nov 2005'
    and not exists (
    select *
    from outstanding_balance ob2
    where ob2.dt_cats_date = '18 Nov 2005'
    and ob2.id_entity = ob1.id_entity
    and ob2.id_object_type = ob1.id_object_type
    and ob2.id_object = ob1.id_object
    and NVL(ob2.id_payment_control, -1) = NVL(ob1.id_payment_control, -1)
    Rows Returned is 34.
    Shouldnt this also return 38? Have I overlooked my NOT EXISTS somewhere?

    Have you tried with NOT IN instead of NOT EXISTS? They really behave differently.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:16307188002894201762::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:442029737684
    Jaffar

  • Frm- 40505 Unable to query (table does not exist)

    Hey,
    I have a form which has two blocks that are master and detail blocks. On the form, there are 3 fields that allow the query. If there is record found in the master then it works fine. If nothing found, it shows "query causes no records" which is also fine. But afterwards, no matter what I type in to query, it always show frm-40505. Oracle error, unable to perform query. I click "display error", it shows:
    SELECT ROWID,LOC,INV_NUMBER,RECNO,FACTOR,C_DESC,ADJ_TYPE,CODE,AMT FROM OE_INVOICE_ADJ
    WHERE (LOC=:1) and (INV_NUMBER=:2) order by recno
    frm - 09402:Table or view does not exist.
    Here oe_invoice_adj is the detail table and it does exist. If I stop the form and run it again then it's fine. It only happens after "query causes no records".
    Any ideas? thanks a lot in advance.

    Jay, Have you created public synonym for the tables so that the users don't have to refer the tables with the schema scott.xtable...
    and have the users been given the SELECT privilege to those tables....
    mb
    I actually created the tables and views for my application by logging in as scott/tiger.Now the users I have created with due privileges are just able to log in but unable to perform any query or DML.The error message is FRM 40505'UNABLE TO PERFORM QUERY' which says table or view does not exist.How do I fix this problem?
    Please get me a solution
    Thanks
    Jay

  • Query the values not exist in the table

    We have a table AP_INVOICES_ALL where we have a column INVOICE_NUM, now we are searching INVOICE_NUM from a large set of values of INVOICE_NUM provided by the user.
    I want a query to find the INVOICE_NUM values supplied by user that doesn't exist in AP_INVOICES_ALL table.
    Database version : 11g
    OS : aix 6.1
    Regards,
    Gaurav

    Hi,
    If you are getting values in the table then the above solution is there but if you are getting the values in excel or text file then you need to upload the data into the table by using sql loader or by using external table.
    if the case then
    load data from excel or plain file into oracle table by using sql loader.(loader is server based utility)
    create table in oracle like create table table_name as column specification.
    If you have excel then save it as .csv file and create sql loader control file like
    oPTIONS (SKIP=1)
    load data
    infile 'Path_where_you_saved_csv_file'
    truncate
    into table table_name_you_have_created
    fields terminated by ','
    optionally enclosed by '"'
    trailing nullcols
    (your_column_name)
    {code}
    call control file from command prompt from the path where your control file and csv or plain file resides.
    {code}
    sqlldr userid=user_name/passowrd@database_name control=control_file_name
    {code}
    above will insert data into table.
    now you can use the select query...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Convert NOT IN to NOT EXISTS if possible

    Hi,
    I have this query which is returning the correct results
    SELECT hdr.order_num
                   ,hdr.business_unit_id
                   ,dtl.item_class_id
               FROM xxx.dd_ddhdr hdr
                   ,xxx.dd_dddtl dtl
              WHERE hdr.order_num = dtl.order_num
                AND hdr.business_unit_id = dtl.business_unit_id
                AND dtl.item_class_id NOT IN
                   SELECT cfl1.filtered_column_value
                     FROM sdds.ai_client_filter_list cfl1
                    WHERE cfl1.client_id = 'XXT'
                      AND cfl1.filtered_column_name = 'ITEM_SUBCLASS'
                      AND cfl1.business_unit_id = hdr.business_unit_id
                AND hdr.order_datetime
                BETWEEN to_date('3/28/2007 13:21','mm/dd/yyyy hh24:mi:ss')
                    AND to_date('3/28/2007 13:26','mm/dd/yyyy hh24:mi:ss');I converted the above query to use NOT EXISTS instead of NOT IN as follows:
    SELECT hdr.order_num
                   ,hdr.business_unit_id
                   ,dtl.item_class_id
               FROM xxx.dd_ddhdr hdr
                   ,xxx.dd_dddtl dtl
              WHERE hdr.order_num = dtl.order_num
                AND hdr.business_unit_id = dtl.business_unit_id
                -- AND dtl.item_class_id NOT IN
                AND NOT EXISTS
                   select 1
                     from sdds.ai_client_filter_list cfl1
                    where cfl1.client_id = 'XXT'
                      and cfl1.filtered_column_name = 'ITEM_SUBCLASS'
                      and hdr.business_unit_id = cfl1.business_unit_id
                AND hdr.order_datetime
                BETWEEN to_date('3/28/2007 13:21','mm/dd/yyyy hh24:mi:ss')
                    AND to_date('3/28/2007 13:26','mm/dd/yyyy hh24:mi:ss');The 2nd query does not return any row after converting to NOT EXISTS.
    Any idea to solve this?.
    Thanks!

    You can try this
    SELECT hdr.order_num
                   ,hdr.business_unit_id
                   ,dtl.item_class_id
               FROM xxx.dd_ddhdr hdr
                   ,xxx.dd_dddtl dtl
              WHERE hdr.order_num = dtl.order_num
                AND hdr.business_unit_id = dtl.business_unit_id
                AND NOT EXISTS
                   SELECT noll
                     FROM sdds.ai_client_filter_list cfl1
                    WHERE cfl1.client_id = 'XXT'
                      AND cfl1.filtered_column_name = 'ITEM_SUBCLASS'
                      AND cfl1.business_unit_id = hdr.business_unit_id
                      AND dtl.item_class_id = cfl1.filtered_column_value --<<--- you missed out this
                AND hdr.order_datetime
                BETWEEN to_date('3/28/2007 13:21','mm/dd/yyyy hh24:mi:ss')
                    AND to_date('3/28/2007 13:26','mm/dd/yyyy hh24:mi:ss');Please keep in mind NOT IN and NOT EXISTS acts differently when it comes to NULL values
    Check this out
    select * from emp where empno not in (select mgr from emp)
    select *
      from emp e
    where not exists(select null from emp e1 where e.empno = e1.mgr)We expect the both to return the same result but they dont. Its because of the null value in the mgr column.
    Now modify the NOT IN query like this and check
    select * from emp where empno not in (select mgr from emp where mgr is not null) Edited by: Karthick_Arp on Sep 14, 2009 12:37 AM

  • Minus operator versus 'not exists' for faster SQL query

    Hi everybody,
    Does anyone know if rewriting a query to use the MINUS operator instead of using NOT EXISTS in the query is faster, giving all else is the same?
    Thanks very much!
    Bill Loggins
    801-971-6837
    [email protected]

    It really depends on a bunch of factors.
    A MINUS will do a full table scan on both tables unless there is some criteria in the where clause of both queries that allows an index range scan. A MINUS also requires that both queries have the same number of columns, and that each column has the same data type as the corresponding column in the other query (or one convertible to the same type). A MINUS will return all rows from the first query where there is not an exact match column for column with the second query. A MINUS also requires an implicit sort of both queries
    NOT EXISTS will read the sub-query once for each row in the outer query. If the correlation field (you are running a correlated sub-query?) is an indexed field, then only an index scan is done.
    The choice of which construct to use depends on the type of data you want to return, and also the relative sizes of the two tables/queries. If the outer table is small relative to the inner one, and the inner table is indexed (preferrable a unique index but not required) on the correlation field, then NOT EXISTS will probably be faster since the index lookup will be pretty fast, and only executed a relatively few times. If both tables a roughly the same size, then MINUS might be faster, particularly if you can live with only seeing fields that you are comparing on.
    For example, if you have two tables
    EMPLOYEE
    EMPID      NUMBER
    NAME       VARCHAR2(45)
    JOB        VARCHAR2(45)
    HIRE_DATE  DATE
    and
    RETIREE
    EMPID      NUMBER
    NAME       VARCHAR2(45)
    RET_DATE   DATEIf you wanted to see if you had retirees that were not in the employee table, then you could use either MINUS or NOT EXISTS (or even NOT IN, but you didn't ask). However you could possibly get different results.
    SELECT empid,name
    FROM retirees
    MINUS
    SELECT empid,name
    FROM employeeswould show retirees not in the emp table, but it would also show a retiree who had changed their name while retired. A safer version of the above using MINUS would be
    SELECT empid,name
    FROM retirees
    WHERE empid IN (SELECT empid
                    FROM retirees
                    MINUS
                    SELECT empid
                    FROM employees)A full scan of retirees, a full scan of employees (Assuming indexes on both, then maybe an index fast full scan) and two sorts for the minus, at best an index probe then table access by rowid on retirees, possibly a full scan of retirees for the outer query.
    Assuming that employees is indexd on empid then
    SELECT empid,name
    FROM retirees
    WHERE NOT EXISTS (SELECT 1
                      FROM employees
                      WHERE retirees.empid = employees.empid)requires a full scan of retirees and an index access into employees index for each row.
    As with most things SQL, the only real way to tell is to benchmark.
    HTH
    John

  • Re NOT EXISTS SQL QUERY

    Hai ,
    I am having doubt regarding NOT EXISTS sql query,
    I want to select rows from table1 where column2 < column3 and column1 value should not exists in another two tables.
    When i tried with NOT IN clause i got the answer but i didnt get when i tried with NOT EXISTS.....can anyone give me the answer....
    select * from TABLE1 where mark2< mark3 AND
    name NOT IN (select name from TABLE2 UNION
    select name from TABLE3);

    Your query can be re-written in the following way by using not exists clause:
    SELECT     *
      FROM     table1 t1
      WHERE     mark2 < mark3
      AND     NOT EXISTS (
           SELECT     1
             FROM     table2
             WHERE     name = t1.name)
      AND     NOT EXISTS (
           SELECT     1
             FROM     table3
             WHERE     name = t1.name)Go through http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:442029737684
    on when to use NOT IN and NOT EXISTS.
    Hope this is helpful.
    - RK

  • Using exist/ not exist

    Hi, can anyone help me design a query which will give me all expertise(exid) which do not have any employees associated with it, using not exist?
    emp (empid, xxx..x..)
    skl (skillid, empid, exid)
    exp(exid, xxx,xxx)
    thanks

    user12258774 wrote:
    hmm, what would be select 1?Does not matter. You can put anything you want. EXISTS/NOT EXISTS cares if select returns rows or it does not. It does not care how many columns or what are the values. In fact, it does not even calculate selected expressions (optimization) so you can put something like 1/0 and still it will work:
    SQL> select deptno from dept d where not exists (select 1/0 from emp e where e.deptno = d.deptno)
      2  /
        DEPTNO
            40
    SQL> SY.

  • Not exists

    I want to select the employees details from emp table except deptno no 20 using not exists operator
    select * from emp where deptno not in(20)
    instead of NOT IN operator how can we rewrite the above query using Exists or NOT EXISTS operator?

    select * from emp a where not exists
    (select null from emp b where deptno=20 and a.deptno=b.deptno) ;Edited by: PhoenixBai on Aug 29, 2010 7:06 PM

  • Query parameter transaction,Query transported but not found in QAS

    Hello all,
    I have an issue with my custom transactions pointing to queries I created. Here is one of 2 examples:
    I have a query in the Global and Standard areas in DEV. Here are my transaction parameters from SE93:
    D_SREPOVARI-EXTDREPORT     QUE_JPTREMB_02
    D_SREPOVARI-REPORTTYPE     AQ
    D_SREPOVARI-REPORT     /SAPQUERY/H2/QUE_JPTREMB_02
    This works perfectly fine in DEV, in all the clients.
    I transported the query using the Export/Import function to QAS. My query in QAS exists only in the Standard Area. I am not able to export/import queries from the global area.
    When I try to run the transaction in QAS, I get the following message:
    "Query QUE_JPTREMB_02 does not exist in user group /SAPQUERY/H2"
    Can any one tell me what is going on here? How can I resolve this issue? Does this have anything to do with global VS standard areas? How do I point the transaction to the Standard Area if that's the case?
    All help appreciated, thank you so much.

    Hi Jean,
    What are the steps you have followed? If I remember correctly the following must be carried out in the following sequence.
    1) Use RSAQR3TR to export the query, usergroup and infoset in dev system.
    2) release the transports in Dev.
    3) import the transports into QAS using STMS (normal Transport mechanism)
    4) import the  query, usergroup and infoset into QAS using  RSAQR3TR
    5) identify the ABAP program associated with the query in QAS system.
    6) create a Transaction code in dev system, assign it to the same query program (even if it does not exist in DEV) and transport the tcodes into QAS.
    7) Execute the query once using SQ01 and then try again using the transaction code.
    (I do not know why steps 6 and 7 are necessary, but that is the way they have worked for me, if I omit the steps, the query program dumps)
    Anyway, I hope the above helps.

  • How to transport Query variant used in APD

    Hello Experts,
    I have created 2 query variants for a query in Development system. And, these variants are being used in APD. Now, when APD is transported to next system, query variants does not exist in next system, so cannot execute APD.
    Please let me know how can i transport the query variants.
    Note: Gone through SDN, and found, query variants can be transported through some tables.
    Please let me any other possibile sloutions for the same.
    Thanks
    Lavanya

    Hi Lavanya,
    To the best of my  knowledge, you cannot transport query variants. You have to manually create them in each system. The reason being, when you try to create variants through RSRT -> Query Variants, you are basically trying to create variants for a temporary program generated during run time!
    These run time programs do not have TADIR entries (not transportable) and hence any sub elements (like variants) created on these programs are not transportable as well.
    Actually you can export variants.Please follow the below steps:
    1. Go To TCode SE38.
    2. Execute "RSTRANSP".
    3. Input your program name.
    4. Input your variant name ie. "Z**** ".
    5. Execute.
    6. Click on continue.
    7. You should be able to create a new transport at this point.
    Hope It Helps,
    Thanks,
    Amit Kr.

  • " "  versus to 'NOT EXISTS'

    I have created a 2 SQL's. The query have the same output. The 1st SQL is using "<>" condition while the other is 'NOT EXISTS' condition. From the TKPROF output, they have the same output. I thought 'NOT EXISTS' is better. Can you please help to interpret TKPROF. Will there be a performance improvement if I used 'NOT EXISTS' in the condition. Appreciate any help. Thanks.
    SQL ID : 0a730aqwqgha1
    SELECT COUNT(*)
    FROM
    ASTG_TRIMPRICES.TP_BOND_ACCRUAL A, AODS.SRV_PRC_BOND_ACRL B WHERE
      A.CLIENT_ID = B.CLIENT_ID AND A.TID = B.SERVICER_INSTR_ID AND A.SETTLE_DATE
      = B.SETTLE_DTE AND A.STG_BATCH_ID <> B.ODS_BATCH_ID
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     20.55      21.53       2918      10087          0           1
    total        3     20.55      21.53       2918      10087          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 133     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=10087 pr=2918 pw=2918 time=0 us)
        712   HASH JOIN  (cr=10087 pr=2918 pw=2918 time=32264 us cost=10694 size=78212640 card=1303544)
    1722766    PARTITION LIST SINGLE PARTITION: 1 1 (cr=4829 pr=0 pw=0 time=20797 us cost=2602 size=50455860 card=1681862)
    1722766     TABLE ACCESS FULL SRV_PRC_BOND_ACRL PARTITION: 1 1 (cr=4829 pr=0 pw=0 time=11845 us cost=2602 size=50455860 card=1681862)
    2118159    TABLE ACCESS FULL TP_BOND_ACCRUAL (cr=5258 pr=0 pw=0 time=13738 us cost=2859 size=63544770 card=2118159)
    SQL ID : dwy21adcrpf8s
    SELECT COUNT(*)
    FROM
    AODS.SRV_PRC_BOND_ACRL B WHERE NOT EXISTS (SELECT 'X' FROM
      ASTG_TRIMPRICES.TP_BOND_ACCRUAL A WHERE A.CLIENT_ID = B.CLIENT_ID AND A.TID
      = B.SERVICER_INSTR_ID AND A.SETTLE_DATE = B.SETTLE_DTE AND A.STG_BATCH_ID =
      B.ODS_BATCH_ID)
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     21.17      21.79       2917      10086          0           1
    total        3     21.17      21.80       2917      10086          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 133     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=10086 pr=2917 pw=2917 time=0 us)
        712   HASH JOIN ANTI (cr=10086 pr=2917 pw=2917 time=1798 us cost=10694 size=60 card=1)
    1722766    PARTITION LIST SINGLE PARTITION: 1 1 (cr=4829 pr=0 pw=0 time=21040 us cost=2602 size=50455860 card=1681862)
    1722766     TABLE ACCESS FULL SRV_PRC_BOND_ACRL PARTITION: 1 1 (cr=4829 pr=0 pw=0 time=11929 us cost=2602 size=50455860 card=1681862)
    2118159    TABLE ACCESS FULL TP_BOND_ACCRUAL (cr=5257 pr=0 pw=0 time=13623 us cost=2859 size=63544770 card=2118159)
    ******************************************************************************** 

    probably, optimizer transformer is rewriting your queries, so in both sql run as same way. about performance of exists operator is depend to tables record count and some other things too. you should try and see the performance.

  • Not exists - seems confused

    hi,
    i think i am confused with my own sql statement
    select * from tbl1 A
    where not exist (select null from tbl2 B
    where a.id = b.id and
    a.createdate between b.start and b.end)what the above query will return are records from tbl1 other than having the same id and between the date range right ?
    my intention is to return all records from tbl1 that might have the same id BUT not between the data range
    i am trying not to do a join as it'll return duplicates but how can i rewrite it using NOT EXISTS
    pls advise
    tks & rdgs

    hi ,
    here's my sample data
    tbl1
    id createdate
    1 12-nov-2006 4 am -- shld not return this record
    1 12-nov-2006 8 am -- shld return this record as it not in the range
    1 12-nov-2006 8:30 am -- shld return this record as it not in the range
    tbl2
    id start end
    1 12-nov-2006 3 am 12-nov-2006 6 am
    1 12-nov-2006 9am 12-nov-2006 12 pm
    2 12-nov-2006 9am 12-nov-2006 12 pm
    hope it'll help to make it clearer
    tks & rdgs

Maybe you are looking for

  • How to implement AZAX call for a input field in webdynpro java.

    Hello everyone, I want to make a AZAX call , when I click on the input field.Anybody has already implemented this earlier, plz let me know how to do this. Thanks, Srikanta

  • Working with word bookmarks

    hi , I have a word file ( all office versions) , which has bookmarks in it . I open it from my application , take data from DW , and  fill each of those bookmarks by its name I want  to scan the file and find all those bookmarks names before i do tha

  • Java editor for Linux

    Which is the best java editor for Linux ?? in the Win plataform I'm using the JCreator ... and now I'm migrating to the linux plataform... please tell me the name of the editor you are using if you use Linux... (Red Hat 7.1 here...)

  • Connecting Linux to Windows NT oracle Databases

    Help- I am trying to connect linux based Websites with an oracle Database running on WinNt... I am not sure what I have to do exactly, I know with Sybase you have to download a certain set of Libs and Rpms, but I am not sure what the deal with oracle

  • How do i block junk email ?!

    I always get email from things i signed and stop using