Query for Existing Records( to improve performance)

Hi Friends,
I want to show only those records from A Table which is not in B Table.
Table A--
Ticket no Ticket date
1 01-01-2009
2 02-01-2009
3 02-02-2009
Table B---
Ticket no Ticket date
3 02-02-2009
means only 1,2 should show.
I am using EXISTS
select ticket_no,ticket_date
from A
where not exists( select '1'
from B
where B.ticket_no=A.ticket_no
and B.ticket_date=A.ticket_date
is any other way to improve my query ?
Help me out.
KarTiK PareeK.

SomeoneElse wrote:
That should reduce cost up to 20%.That's doubtful.
BTW: joins and operator sets will be much slower that EXISTS in that case.Maybe, maybe not.
It's possible that the two queries wouldn't return the same results, so they wouldn't be comparable anyway.
Minus also does a sort to eliminate duplicates. But maybe that's what the OP wanted.
Of course, as usual we didn't get any sample tables, data, results...I wrote that based on my own research. I created two tables, populated them with sample data (1,000,000 rows each).
What I wrote about 20% decrease in cost, was based on query time consumption and explain plan before and after analyzing tables.
In my case, joins were slower. USE_* hints didn't help. MINUS was slower also.

Similar Messages

  • Alternate for inner join to improve performance

    Hi all,
    I have used an inner join query to fetch data from five different tables into an internal table with where clause conditions.
    The execution time is almost 5-6 min for this particular query(I have more data in all five DB tables- more than 10 million records in every table).
    Is there any alternate for inner join to improve performance.?
    TIA.
    Regards,
    Karthik

    Hi All,
    Thanks for all your interest.
    SELECT  a~object_id a~description a~descr_language
                a~guid AS object_guid a~process_type
                a~changed_at
                a~created_at AS created_timestamp
                a~zzorderadm_h0207 AS cpid
                a~zzorderadm_h0208 AS submitter
                a~zzorderadm_h0303 AS cust_ref
                a~zzorderadm_h1001 AS summary
                a~zzorderadm_h1005 AS summary_uc
                a~zzclose_date     AS clsd_date
                d~stat AS status
                f~priority
                FROM crmd_orderadm_h AS a INNER JOIN crmd_link AS b ON  a~guid = b~guid_hi
                INNER JOIN crmd_partner AS c ON b~guid_set = c~guid
                INNER JOIN crm_jest AS d ON objnr  = a~guid
                INNER JOIN crmd_activity_h AS f ON f~guid = a~guid
                INTO CORRESPONDING FIELDS OF TABLE et_service_request_list
                WHERE process_type IN lt_processtyperange
                AND   a~created_at IN lt_daterange
                AND   partner_no IN lr_partner_no
                AND   stat IN lt_statusrange
                AND   object_id IN lt_requestnumberrange
                AND   zzorderadm_h0207 IN r_cpid
                AND   zzorderadm_h0208 IN r_submitter
                AND   zzorderadm_h0303 IN r_cust_ref
                AND   zzorderadm_h1005 IN r_trans_desc
                AND   d~inact = ' '
                AND   b~objtype_hi = '05'
                AND   b~objtype_set = '07'.
                f~priority
                FROM crmd_orderadm_h AS a INNER JOIN crmd_link AS b ON  a~guid = b~guid_hi
                INNER JOIN crmd_partner AS c ON b~guid_set = c~guid
                INNER JOIN crm_jest AS d ON objnr  = a~guid
                INNER JOIN crmd_activity_h AS f ON f~guid = a~guid
                INTO CORRESPONDING FIELDS OF TABLE et_service_request_list
                WHERE process_type IN lt_processtyperange
                AND   a~created_at IN lt_daterange
                AND   partner_no IN lr_partner_no
                AND   stat IN lt_statusrange
                AND   object_id IN lt_requestnumberrange
                AND   zzorderadm_h0207 IN r_cpid
                AND   zzorderadm_h0208 IN r_submitter
                AND   zzorderadm_h0303 IN r_cust_ref
                AND   zzorderadm_h1005 IN r_trans_desc
                AND   d~inact = ' '
                AND   b~objtype_hi = '05'
                AND   b~objtype_set = '07'.

  • Query  for getting records  max  reported  timestamp and 2nd max report

    query for getting records in between
    max reported timestamp and 2nd max reported timestamp
    HERE IS ALL RESULT SET
    TIME DOMAIN
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    QUERY RESULT TO COME
    TIME DOMAIN
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    Message was edited by:
    user517983

    Hi,
    can we write query like this.
    1 select pd_user,PD_REPORTED_TIMESTAMP
    2 from sp_process_detail_current spdc
    3 where host_id='DSCP02469'and pd_user='TOMCAT'
    4 and exists(
    5 select PD_REPORTED_TIMESTAMP from sp_process_detail_current
    6* having max(PD_REPORTED_TIMESTAMP)-spdc.PD_REPORTED_TIMESTAMP=0)
    SQL> /
    PD_USER PD_REPORTED_TIMESTAM
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45

  • Disabling the dropdown LOV for existing records in SQL updateable report

    Hi All -
    I have a SQL updateable report which has 3 columns. One of the column is a named-LOV. This report also provides the functionality of inserting new rows.
    Is there a way to only show the named-LOV dropdown list for only the new records to be inserted i.e. when we click on "Add Row". For existing records, I donot want to show the dropdown.
    Please provide your thoughts.
    Thanks,
    -Seenu

    Thanks Robert -
    I guess I didn't put my question right in my earlier posting.
    Basically this report provides updates and inserts both (Its a SQL Updateable report)
    One of the column is a Named-LOV (select list dropdown). For the existing records shown in this report, this select list should be disabled. But for the new records while inserting a new row into this report, the select list dropdown should be shown to the user with an option to choose values from selectlist.
    Thanks,
    -Seenu

  • How to model query for -- existing and unchanged values

    Hello BW Experts,
    I have material and material group as navigational time-dependent attributes. I have a requirement to show the existing and unchanged values for the material and material group in the time frame 2003 to 2006 . how to create a query for this.
    Suggestions appreciated.
    Thanks,
    BWer

    HI ,
    I think u need to add two more date fields as the attributes  to the master data and then use them and give restriction in the query with the Keydate to see data which has unchanged from One range to another . As key Date applies to only the system defined to and from dates present in the Master Data .
    In query give Keydate as 31.dec.2006 and then give restriction for user defined dates sa follows :
    User From : 01.01.1000 - 31.12.2002.
    User To : 01.01.2007 -- 31.12.9999 .
    Regards,
    Vijay.
    Message was edited by: vijay Kumar
    Message was edited by: vijay Kumar
    Message was edited by: vijay Kumar

  • How to create idocs  for  existing records

    Hi
    are there any standard program by which i could create and send the existing customer invoice (VF01) data thru EDI idoc to a 3rd party system even if the output type is not defined during the creation of the invoices?
    Regards
    Sujai

    I am supposed to send all customer invoice data to an external system. I have been able to configure the system to trigger an idoc when an invoice is saved. That takes care of my delta transfer. But i would like to know if there is a way by which i can send all the existing customer invoice data to the 3rd party system that were already created in the SAP system. Something like an initial download of all the existing records.
    I am asked to keep the abap development to Zero as far as possible, hence i am exploring the idea of finding any standard program that could do this for me.
    just like Tx: BD10 for the material master data.
    I tried VF31 but the problem is that the invoice that would have been created might not contain the output type as EDI. So is there a way by which i can achieve this task with any standard program?
    I also have another question:
    how do i do the configuration to send all the SD invoices to a specific partner all the time thru EDI by default?
    Sujai

  • Writing OR query for fetching records

    Hi,
    I have dowloaded a custom wsdl and generated a java client from it using Jdeveloper.
    I have a method named customObject1QueryPage(QueryInputObj) which is used to query the CRM oD to fetch records.
    I have successfully queried using the above method for one condition:-
    QueryInputObj param= new QueryInputObj();
    QueryType q = new QueryType();
    q.set_value("='" + "ABC'");
    //q.set_value("LIKE 'A*'");
    param.setAccountName(q);
    customObject1QueryPage(param);
    But now I want to query using "OR" condition with multiple names in the condition and I don't know how to
    write query for that.
    SQL query would be like "Select * from table where name='ABC' OR name='PQR' OR name ='XYZ' ";
    I want to execute same query for CRM oD but have no idea how to write it.
    Can somebody please help me as soon as possible.
    Thanks.

    Hi,
    If your intent to Use OR Condition on a field with multiple Values
    say, AccountName = 'xyz' OR AccountName= 'abc' the syntax would be *(='xyz') OR (='abc')*
    say, AccountName = 'xyz' OR AccountName= 'abc' OR AccountName = 'pqr' the syntax would be *((='xyz') OR (='abc'))OR(='pqr')*
    You can find similar example under On Demand Web Service Documentation
    Regards
    Deepak H Andeli

  • BDC for existing record in table control

    Hi,
    I have a requirement to change existing records in table control through BDC. Is there any way I can choose the respective record from Table Control through BDC dynamically.
    Regards
    Akash

    /J4I/015PER, this transaction is used for adding permits to Operation in WEC. It has list of operations in Table Control. Permit can be added for choosing the operation from table control.
    Our custom program is designed to add permits for the operation. So if I have to use the above transaction for adding permits, then first I have to choose the correct operation from the table control and then add permit.

  • How  to fire a query for every record in a table, pass values in a loop

    Hi,
    For each record in a table, I want to loop through each record and then fire a query by passing acct, product and date from this table to the where clause of the query. I would have to create a pl/sql block..The output of the query I want to spool from sql developer.
    I need the exact syntax please for doing this.. since i am new to Oracle. Just the template will be enough. I will fill in the query.
    Any help is appreciated as always..
    Regards,
    hena

    904385 wrote:
    Hi,
    For each record in a table, I want to loop through each record and then fire a query by passing acct, product and date from this table to the where clause of the query. I would have to create a pl/sql block..The output of the query I want to spool from sql developer.
    I need the exact syntax please for doing this.. since i am new to Oracle. Just the template will be enough. I will fill in the query.
    Any help is appreciated as always..
    Regards,
    henaHave you ever considered using a JOIN ? It does the same thing as looping through a table and applying that to the where clause of a select on a query, only much, much, much faster and without the need to write any code. SQL is a declarative language, so you specify what you want and not how to do it. It can be bit of a journey to change your thought process if you come from a procedural or object world, but once you get there it's a beautiful view.

  • Workflow rules doesn't work for existing record!!?!?!?

    Hi all,
    I've created one workflow rule to update value from one filed to another. Here is my expression:
    [<QuickSearch1>] <> [<plStatus_ITAG>]
    and my action is
    field name = "*Status" (QuickSearch1)
    Value = <plStatus_ITAG>
    and I tick on the Overwrite the existing value
    This is work for new record, but for the existing one the field value doesn't chnage. Any suggestion??
    Thanks
    Note

    The syntax should be: PRE('< QuickSearch1>') <> [<QuickSearch1>] for the condition.

  • Querying for existing set of values

    HI,
    I have the following scenario. I have one table which has the measure_id,measure_value and date.
    For every date, I will be populating the measure_value for every measure_id. 
    If the source, doesnt have the value for a day,for a measure_id, I should update it with 0.
    If the source gets fresh data for a date, then the related value should get updated(sum of values for that day) or inserted.(incremental)
    DATE MeasureID MeasureValue
    02/01  1 10
    02/01  2 20
    02/01  3 30
    02/02  1 10
    02/02  2 0(no data in source)
    02/02  3 30
    Can you please give me the best query for this scenario. Any help is appreciated.
    Porus

    you can try using Merge command.
    I have used some sample data in Source and Destination tables.Also i used a measures table with three measure.
    Declare @Source Table(Dt Date, MeasureID int, MeasureValue int);
    Declare @Destination Table(Dt Date, MeasureID int, MeasureValue int);
    Declare @Measure Table (MeasureID int);
    Insert into @Measure select 1 union all select 2 union all select 3
    Insert into @Source
    select '20140201',1,10
    union all
    select '20140201',2,10
    union all
    select '20140201',3,10
    union all
    select '20140202',1,10
    union all
    select '20140202',3,30
    Insert into @Destination
    select '20140201',1,0
    select * from @Source
    select * from @Destination
    ;With AllMeasures
    as
    select * from
    (SELECT distinct Dt from @Source) A
    cross join @Measure
    MERGE @Destination AS target
    USING
    select A.Dt,A.MeasureID,isnull(S.MeasureValue,0) from AllMeasures A
    left join @Source S on A.Dt=S.Dt and A.MeasureID=S.MeasureID
    ) AS source (Dt, MeasureID,MeasureValue)
    ON (target.Dt = source.Dt and target.MeasureID = source.MeasureID)
    WHEN MATCHED THEN
    UPDATE SET MeasureValue = source.MeasureValue
    WHEN NOT MATCHED THEN
    INSERT (Dt, MeasureID,MeasureValue)
    VALUES (source.Dt,source.MeasureID,source.MeasureValue);
    select * from @Destination
    Vinay Valeti| If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer

  • Improving SQL query for large records.

    I need to extract the difference on the table t1 and t2(contains both almost 6M records). Im looking specifically on the two columns (c1,c2)for my comparison.I need also to look at reference table to extract also other fields for my report. thank you
    Dynamic Table (same table and structure but different records.)
    t1
    t2
    Reference Static Table (all the tables below have two columns. c1 and c2 used for reference only)
    t3
    t4
    t5
    --Extracting data in t1 but not exists in t2
    WITH v1 AS(SELECT c2,c3,c4 FROM t1 at1
    WHERE NOT EXISTS (SELECT 'x' FROM t2 at2 WHERE at1.c1 = at2.c2)),
    v2 AS (SELECT c1, c2 FROM t3),
    v3 AS (SELECT c1, c2, c3 FROM t4),
    v4 AS (SELECT c1,c2 FROM t5)
    SELECT v1.c1, v1.c2, v3.c2, v4.c2 FROM t,t2,t3,t4
    WHERE v1.c1 = v2.c1
    AND v2.c2 = v3.c1
    AND v3.c2 = v4.c1
    ORDER BY v1.c1
    I'm trying to improve my scripts to generate the record as fast as possible coz it takes too long. Any suggestions guys.? Im trying to look also on explain plan but I'm new on this. thank you

    Hi,
    your sample code can not compile?
    There is no column c1 in the v1?
    Probably a typo anyway :)
    A couple of remarks:
    The way you've used v1, v2, v3 and v4 does not help performance.
    It only helps increasing the confusion.
    Rewrite the query without the WITH clause, post the execution plan for the query and report your Oracle version and we can help you further.
    / Ronnie

  • Query for next record in a multiple records display

    Hi. I have a text item whose data block displays 10 records after post query. I want to put a query on the keyboard up and down button so that when i press the up or down arrow of the keyboard, the cursor moves to the next record and executes the post query trigger. I tried using the next_record command but the cursor remains on the first record and then tries to create a new record there instead of moving to the next record outputted by the initial post query trigger. I hope you get my point. Thanks

    Hi,
    I have a text item whose data block displays 10 records after post query. <b>I want to put a query on the keyboard up and down button so that when i press the up or down arrow of the keyboard</b>, the cursor moves to the next record and executes the post query trigger. I tried using the next_record command but the cursor remains on the first record and then tries to create a new record there instead of moving to the next record outputted by the initial post query trigger. I hope you get my point. You do not have to query again for moving cursor up and down. You have to use KEY-UP and KEY-DOWN with NEXT_RECORD and PREVIOUS_RECORD built-ins. Use FIRST_RECORD and LAST_RECORD for boundary conditions.
    Regards,

  • Tunning the query for faster record retrieval

    Hi,
    I am back, now this time I donot really know in which forum I should post this query, in XML or in Oracle Developers ?
    Anyway...
    The problem is :
    I have a database with millions of record in that, I give a query based on some 4/5 parameters, and retrieve the records corresponding to that, I have added indexes in the database for faster retrieval of the same, but since the no of records returned is quite high and I planned to put a prev and next link to show only 10 records at a time, I had to get the count(*) of the number of records that match, here is the problem, since there are so many records, and count(*) doesn't consider index, it takes nearly 20-30 seconds for the retrieved list to be seen on the browser window, if I just remove that count(*), the retrieval is quite fast, but then there is no prev and next as I had linked them to count(*).
    Could some one please let me know the proper way of doing it. I am a newbie to this and I have been doing some trial and error to get my work done.
    Thanks in advance,
    Regards,
    Shanthi Rajaram

    Make sure to select the COUNT() of an indexed column (the more selective the index the better), this way the optimizer can satisfy the count query with a few IO's of the index blocks instead of a full-table scan.

  • Need a query for duplicate records deletion

    here is one scenario...
    23130 ----> 'A'
    23130 ----> 'X'
    23130 ----> 'c'
    These are duplicate records.. when we remove duplicates, the record must get 'c', if it contains A,C,X. If it contains A and X, then the record must get 'X'. That means the priority goes like this C-->X-->A. for this i need query.. this is one scenario. It would be great if u reply me asap.

    Hello
    It's great that you gave examples of your data, but it is quite helpful to supply create table and insert statements too along with a clear example of expected results. Anyway, I think this does what you are looking for.
    CREATE TABLE dt_dup (ID NUMBER, flag VARCHAR2(1))
    INSERT INTO dt_dup VALUES(23130, 'A');
    insert into dt_dup values(23130, 'X');
    insert into dt_dup values(23130, 'C');
    INSERT INTO dt_dup VALUES(23131, 'A');
    INSERT INTO dt_dup VALUES(23131, 'X');
    DELETE
    FROM
      dt_dup
    WHERE
      ROWID IN (  SELECT
                    rid
                  FROM
                    (   SELECT
                          rowid rid,
                          ROW_NUMBER() OVER (PARTITION BY ID ORDER BY CASE
                                                                        WHEN flag = 'A' THEN
                                                                          3
                                                                        WHEN flag = 'X' THEN
                                                                          2
                                                                        WHEN flag = 'C' THEN
                                                                          1
                                                                      END
                                            ) rn
                        FROM
                          dt_dup
                  WHERE
                    rn > 1
    select * from dt_dup;HTH
    David
    Edited by: Bravid on Jun 30, 2011 8:12 AM

Maybe you are looking for

  • CSV spreadsheet returning "no data found"

    Hi, In one of the reports, I enabled CSV Output so the report can be downloaded. When I download it, using Excel 2000, I have no problem, I can see all the right data. However, one of my user, who uses Excel 2002, when saves the file and opens it, re

  • How can I create an app without using a Mac?

    I want to create my own apps for my iPhone. How can I do that when I have a Windows computer?

  • Sharing iTunes library between two accounts on a single iMac

    My wife and I are using the same iMac but through 2 separate accounts, which is quite neat to separate files, preferences, etc. We have 'ripped' our home CD collection into the iTunes library of my account, and I am now looking for a way for my wife

  • Hard drive and Lion problems

    Since trying to do the Lion update on Weds my iMac has been playing up, basically when i going into disk utility and run "verify disk" i get error messages telling me to insert my OS X install cd so that i can repair the hard drive, i do this and whe

  • IMac 10.4.4 crashes using Safari 2.0.3

    I'm trying to help out my dad, who's using an iMac that's running 10.4.4. He's never updated Safari from his current 2.0.3. He's started having problems with Safari quitting without notice. I've tried to download the 3.1 version of Safari and the 4.B