How to tune the query for duplicate records while joining the two tables

hi,i am executing the query which has retrieving multiple tables,in which one of them has duplicate record,how to get single record

Not enough info...subject says "tune" the query, message says "write" the query...and where is actual query that you had tried ?

Similar Messages

  • How to tune this query for the improve performance ?

    Hi All,
    How to tune this query for the improve performance ?
    select a.claim_number,a.pay_cd,a.claim_occurrence_number,
    case
    when sum(case
    when a.payment_status_cd ='0'
    then a.payment_est_amt
    else 0
    end
    )=0
    then 0
    else (sum(case
    when a.payment_status_cd='0'and a.payment_est_amt > 0
    then a.payment_est_amt
    else 0
    end)
    - sum(case
    when a.payment_status_cd<>'0'
    then a.payment_amt
    else 0
    end))
    end as estimate
    from ins_claim_payment a
    where a.as_of_date between '31-jan-03' and '30-aug-06'
    and ( a.data_source = '25' or (a.data_source between '27' and '29'))
    and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
    group by a.claim_number, a.pay_cd, a.claim_occurrence_number
    Thank you,
    Mcka

    Mcka
    As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
    And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
    Regards Nigel

  • 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

  • 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.

  • How to execute the query for a block based on the parameter

    Hi All,
    Good evening.
    i have requirement where i need to display the data in one block based on the selected items.
    the scenario is like this...there are 2 LOV's and one apply button and one external region on the form.
    so when u select the lov values and click on apply button the query should execute based on this 2 lov values.
    i am not getting how to achieve this..i am very new to oracle forms..
    Please Help..
    Thanks
    Bharat
    please help..it is urgent..
    thanks
    bharat
    Edited by: Bharat on Jan 31, 2012 5:19 AM

    Bharat wrote:
    Hi All,
    Good evening.
    i have requirement where i need to display the data in one block based on the selected items.
    the scenario is like this...there are 2 LOV's and one apply button and one external region on the form.
    so when u select the lov values and click on apply button the query should execute based on this 2 lov values.
    i am not getting how to achieve this..i am very new to oracle forms..Another way you can do this. Create a lov and don't assign it to any column just one return item (should be id).
    Now create a button may be your "apply button" write two trigger when-button-press and when-mouse-click.
    at When -Button-Press trigger, change the block state to 'ENTER-QUERY' and at when-mouse-click show the LOV and then write execute_query.
    Hope this will help you.
    If someone's response is helpful or correct, please mark it accordingly.

  • Getting message for every  record while pressing the down arrow

    Hi,
    when i query the form and when I am going through the records by pressing the down arrow of the keyboard I am getting the message 'Do you want to Save the records' for every record.
    How to avoid the message?
    I developed the form in oracle applications and it is a master detail form which have a header block and lines block.

    You are probably changing a value in POST-QUERY trigger, check your trigger and make sure you're not updating any values.
    For Oracle Apps specific questions, I suggest you post in the E Business Suite section of the Forums.
    Tony

  • How to avoid Duplicate Records  while joining two tables

    Hi,
    I am trying to join three tables, basically two tables are same one is like history table, so I wrote a query like
    select
    e.id,
    e.seqNo,
    e.name,
    d.resDate,
    d.details
    from employees e,
    ((select * from dept)union(select * from dept_hist)) d
    join on d.id=e.id and e.seqno=d.seqno
    but this returing duplicate records.
    Could anyone please tell me how to avoid duplicate records of this query.

    Actually it is like if the record is processed it will be moved to hist table, so both table will not have same records and I need the record from both the tables so i have done the union of both the tables, so d will have the union of both records.
    But I am getting duplicate records if even I am distinct.

  • Recursive query for finding parents and children against two tables

    Hi I have two tables where the data is stored hierarchially.
    I have found using connect_by, level and other oracle functions doing its job when the data is in one table.
    Can I traverse against two tables by using the same oracle functions.
    My Table A can go 2 levels deep in my hierarchy and level 3 and so forth has to be done against a different table.
    Appreciate your insight..
    Thanks in advance

    The number of levels that I can traverse in the first table is dynamic (sometimes 2 levels and sometimes 3 levels and actually no level limit) and then has to dynamically start looking at second table for finding any more levels in the other table.
    I was able to implement them seperately and union them.
    I was more looking for a comprehensive solution to reduce the number of lines that I have to maintain...
    Thanks in advance
    Edited by: user566193 on Jan 15, 2010 1:58 PM

  • How can I save previews for old projects, while burning the project to DVD?

    I'll admit, I haven't read the user manual cover to cover (or screen to screen for the electronic version), and haven't spent hours combing the discussions here, but I have searched for all the relevant keywords I can think of and can't find a concise answer to this question.
    I get the basic idea of Vaults (I think), but haven't found much info about long term storage of projects. I'm fulltime freelance, but not super busy, and I can easily generate 100,000 images each year. I don't have the cash to be keeping all of these images in Aperture projects on external hard drives for eternity, and I'd be surprised if anyone else does. Good thing I'm not a medium format digital shooter producing 50GB each day huh?
    I remember seeing a clip of a photographer 2 or 3 years ago discussing the differences between storing digital and film images. He was making the point that throwing away files you don't think you'll need again can be a mistake, citing a shot he had of Clinton and Lewinsky together, before Clinton and Lewinsky were news. "If I'd been shooting digital, that image wouldn't exist today". It was a great pic, and when that whoel scandal erupted, it made him alot of money.
    So at present I'm storing every image I take in finished projects on DVD trusting that in the future I'll be looking for a shot of someone I may have shot 5, 10, 15 years ago.
    I caught part of a discussion that talked about keeping the preview files for all the images (and subsequent versions) for each project. I'd love to be able to keep lo-res previews/copies of everything I've shot to date, and have them immediately accessible on my hard drive, while my full size projects are safely stored on DVD, taking up space on a bookshelf rather than on my hard drive. Loading 10 DVD's worth of projects to see what's inside them is a headache I'd like to avoid if possible, in favour of instantly checking out lo-res previews to look a shot up.
    Is there an easy way to burn a completed project to DVD, but keep only the (lo res, lo size) previews on my hard drive?
    20" iMac and G4 Powerbook   Mac OS X (10.4.8)   "A creative and dynamic professional" (I lie alot and can't sit still)

    hello, kiwi
    quote: "Is there an easy way to burn a completed project to DVD, but keep only the (lo res, lo size) previews on my hard drive?"
    yes.
    maybe,...
    1. you might think of making DVD backups first prior to importing the photos into Aperture. "Store Files: In their current location" once in Aperture make low rez Previews, and export finished Project.
    or,
    2. bring in the photographs to hard drive first prior to importing the photos into Aperture. "Store Files: In their current location" once in Aperture make low rez Previews, and export finished Project.
    the low rez Previews will stay in Aperture but the high quality Versions will be exported onto DVDs and gone from the hard drive (if you delete the originals).
    another way would be to export small about 50-70 pixel wide high quality jpegs to a folder on your Desktop and import & keep these in Aperture Library as a reference. make metadata to show where the original Project DVDs are stored and DVD filing system used.
    victor

  • Update query to fixed value while joining to multiple tables

    We have a lot of phone country codes that are blank or incorrect. For example, Egypt's phone country code is 20. I want to update the phone country code to 20 but only if the country in the locations table = 'EG' and there is in fact a location record (it's possible a party has a phone number but not a physical address in which case there is insufficient information to update the phone country code to 20. Here's what I have thus far which does not work.
    update ar.hz_contact_points hzcp
    set hzcp.phone_country_code = 20
    join ar.hz_party_sites hzps on hzps.PARTY_ID = hzcp.OWNER_TABLE_ID
    join ar.hz_locations hzl on hzl.LOCATION_ID = hzps.location_id
    where 1=1
    and hzcp.owner_table_name = 'HZ_PARTIES'
    and hzl.location_id = hzps.location_id
    and hzl.country = 'EG'
    and hzcp.phone_country_code not like '20'
    and hzcp.contact_point_id = '54060443' --(Note I'm limiting it just to one record for testing.)Thanks in advance!

    Just slightly different
    update ar.hz_contact_points hzcp
       set hzcp.phone_country_code = 20
    where hzcp.phone_country_code != 20
       and hzcp.owner_table_name = 'HZ_PARTIES'
       and hzcp.contact_point_id = 54060443   --(Note I'm limiting it just to one record for testing.)
       and exists(select null
                    from ar.hz_party_sites hzps,
                         ar.hz_locations hzl
                   where hzps.PARTY_ID = hzcp.OWNER_TABLE_ID
                     and hzl.location_id = hzps.location_id
                     and hzl.country = 'EG'
                 )Regards
    Etbin

  • Count for item records reaches 999 the second idoc gets triggered!

    Hi Experts,
         I have an issue. Sender is file and receiver is idoc with a header and item  level records. Only one header and n number of records can be there.
    Now we want to make  this way that as soon as the count for item records reaches 999 the second idoc gets triggered.
      Hints / Solutions Pls.
    Regards,
    Arnab .

    incorporate mapping logic such that for every 999 item records create new IDoc node
    check with this UDF for IDoc node mapping, item records will be input to UDF
    int count = a.length;
    int k=999;
    result.addValue("");
    for(int i=0;i<count;i++)
          if (i>=k){
              result.addValue(""); // if records > 999, add IDoc node
              k=k+999;     
    Do rest of the mapping accordingly

  • How to print out the text for Info record in ME23?

    Dear all,
    I need to print out a report of PO data. need to print out the text from Info record note (like the picture shown below) in ME23, how should I pull that field and display out?
    I need the solution urgently. Hope experts can help.
    Thank you very much.
    [http://img293.imageshack.us/img293/238/inforecordnd1.png]

    Please check below sample code:
    PARAMETERS: p_ebeln TYPE ebeln OBLIGATORY.
    TYPES: BEGIN OF ty_ekpo,
             ebeln TYPE ebeln,
             ebelp TYPE ebelp,
           END OF ty_ekpo.
    DATA: i_ekpo TYPE TABLE OF ty_ekpo,
          wa_ekpo TYPE ty_ekpo.
    DATA: l_name TYPE tdobname,
          i_tline TYPE TABLE OF tline,
          wa_tline TYPE tline.
    CONSTANTS: c_id   TYPE tdid VALUE 'F02',
               c_object TYPE tdobject VALUE 'EKPO'.
    AT SELECTION-SCREEN.
      SELECT SINGLE ebeln INTO p_ebeln
             FROM ekko
             WHERE ebeln = p_ebeln.
      IF sy-subrc NE 0.
        MESSAGE e001(00) WITH 'Enter valid PO Number'.
      ENDIF.
    START-OF-SELECTION.
      SELECT ebeln ebelp INTO TABLE i_ekpo
             FROM ekpo
             WHERE ebeln = p_ebeln.
      LOOP AT i_ekpo INTO wa_ekpo.
        CONCATENATE wa_ekpo-ebeln wa_ekpo-ebelp
           INTO l_name.
        CALL FUNCTION 'READ_TEXT'
          EXPORTING
            id                      = c_id
            language                = sy-langu
            name                    = l_name
            object                  = c_object
          TABLES
            lines                   = i_tline
          EXCEPTIONS
            id                      = 1
            language                = 2
            name                    = 3
            not_found               = 4
            object                  = 5
            reference_check         = 6
            wrong_access_to_archive = 7
            OTHERS                  = 8.
        IF sy-subrc EQ 0.
          LOOP AT i_tline INTO wa_tline.
            WRITE:/ wa_tline-tdline.
            " Format wa_tline-tdline in the way you need to print out
          ENDLOOP.
        ENDIF.
      ENDLOOP.
    Regards
    Eswar

  • Check for duplicate record in SQL database before doing INSERT

    Hey guys,
           This is part powershell app doing a SQL insert. BUt my question really relates to the SQL insert. I need to do a check of the database PRIOR to doing the insert to check for duplicate records and if it exists then that record needs
    to be overwritten. I'm not sure how to accomplish this task. My back end is a SQL 2000 Server. I'm piping the data into my insert statement from a powershell FileSystemWatcher app. In my scenario here if the file dumped into a directory starts with I it gets
    written to a SQL database otherwise it gets written to an Access Table. I know silly, but thats the environment im in. haha.
    Any help is appreciated.
    Thanks in Advance
    Rich T.
    #### DEFINE WATCH FOLDERS AND DEFAULT FILE EXTENSION TO WATCH FOR ####
                $cofa_folder = '\\cpsfs001\Data_pvs\TestCofA'
                $bulk_folder = '\\cpsfs001\PVS\Subsidiary\Nolwood\McWood\POD'
                $filter = '*.tif'
                $cofa = New-Object IO.FileSystemWatcher $cofa_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
                $bulk = New-Object IO.FileSystemWatcher $bulk_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
    #### CERTIFICATE OF ANALYSIS AND PACKAGE SHIPPER PROCESSING ####
                Register-ObjectEvent $cofa Created -SourceIdentifier COFA/PACKAGE -Action {
           $name = $Event.SourceEventArgs.Name
           $changeType = $Event.SourceEventArgs.ChangeType
           $timeStamp = $Event.TimeGenerated
    #### CERTIFICATE OF ANALYSIS PROCESS BEGINS ####
                $test=$name.StartsWith("I")
         if ($test -eq $true) {
                $pos = $name.IndexOf(".")
           $left=$name.substring(0,$pos)
           $pos = $left.IndexOf("L")
           $tempItem=$left.substring(0,$pos)
           $lot = $left.Substring($pos + 1)
           $item=$tempItem.Substring(1)
                Write-Host "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp"  -fore green
                Out-File -FilePath c:\OutputLogs\CofA.csv -Append -InputObject "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp"
                start-sleep -s 5
                $conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=PVSNTDB33; Initial Catalog=adagecopy_daily; Integrated Security=TRUE")
                $conn.Open()
                $insert_stmt = "INSERT INTO in_cofa_pvs (in_item_key, in_lot_key, imgfileName, in_cofa_crtdt) VALUES ('$item','$lot','$name','$timestamp')"
                $cmd = $conn.CreateCommand()
                $cmd.CommandText = $insert_stmt
                $cmd.ExecuteNonQuery()
                $conn.Close()
    #### PACKAGE SHIPPER PROCESS BEGINS ####
              elseif ($test -eq $false) {
                $pos = $name.IndexOf(".")
           $left=$name.substring(0,$pos)
           $pos = $left.IndexOf("O")
           $tempItem=$left.substring(0,$pos)
           $order = $left.Substring($pos + 1)
           $shipid=$tempItem.Substring(1)
                Write-Host "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp"  -fore green
                Out-File -FilePath c:\OutputLogs\PackageShipper.csv -Append -InputObject "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp"
    Rich Thompson

    Hi
    Since SQL Server 2000 has been out of support, I recommend you to upgrade the SQL Server 2000 to a higher version, such as SQL Server 2005 or SQL Server 2008.
    According to your description, you can try the following methods to check duplicate record in SQL Server.
    1. You can use
    RAISERROR to check the duplicate record, if exists then RAISERROR unless insert accordingly, code block is given below:
    IF EXISTS (SELECT 1 FROM TableName AS t
    WHERE t.Column1 = @ Column1
    AND t.Column2 = @ Column2)
    BEGIN
    RAISERROR(‘Duplicate records’,18,1)
    END
    ELSE
    BEGIN
    INSERT INTO TableName (Column1, Column2, Column3)
    SELECT @ Column1, @ Column2, @ Column3
    END
    2. Also you can create UNIQUE INDEX or UNIQUE CONSTRAINT on the column of a table, when you try to INSERT a value that conflicts with the INDEX/CONSTRAINT, an exception will be thrown. 
    Add the unique index:
    CREATE UNIQUE INDEX Unique_Index_name ON TableName(ColumnName)
    Add the unique constraint:
    ALTER TABLE TableName
    ADD CONSTRAINT Unique_Contraint_Name
    UNIQUE (ColumnName)
    Thanks
    Lydia Zhang

  • How do programatically set focus on a record other than the first one in a block?

    My form performs the query for the block, and by default it leaves the focus on the first (top) record in the block.  I'd like to have it focus on the last record in the block upon initial query.
    i've tried Last_record and go_record in a post-block trigger but these builtins are restricted and you can't execute them from post block triggers.  i don't see any block property things that would influence this either...  how can i do it?  thanks.

    i just figured out the answer to my own question... in the when new block instance trigger, there's an execute_query statement, and i simply put last_record statement after that...

Maybe you are looking for

  • SSIS package "The Microsoft Jet database engine cannot open the file"

    Dear all, I am trying to import data from an excel spreadsheet which is save on application sharing server. When I try to save same file locally (On my desktop) my package has no problem to read it.  Problem comes when I change the file path to the s

  • How can i create a BSP system?

    <b></b> Hello All, I need to create a BSP system could u plz provide me any one step by step procedure for me Thanks in advance Bye

  • After upgrade to iOS 5 there is a large chunk of data ( 9Gb) on the phone labeled as "Other" in iTunes.

    After upgrade to iOS 5 there is a large chunk of data (>9Gb) on the phone labeled as "Other" in iTunes. I suspect this is the music library from before the upgrade. How do I delete this data?

  • Installing NIC on SUN ultra 60

    Hi , I have installed a NIC on a Sun ultra60 machine.The part number of the NIC is X1033A. I do not have the drivers for the same.The machine is running SOlaris 2.6.Does the OS have the required drivers for this NIC? When I run the "ifconfig -a" comm

  • Direct conx mac to pc for gaming

    Hello. Can anyone advise how to configure a direct connection via ethernet cable from mac to pc for multiplayer games like starcraft and warcraft? I haven't bought a macbook yet. I've been a mac loyalist since 1990. But I'm in the navy now and while