How to delete records from a table that has a composite unique key duplicate

Hello
I get the customer data from various sources in the staging of the table where I insert in the database table where the combination of two columns is considered as a unique key. But there is a possibility of duplicates. How to find duplicates in a SQL or pl/sql

Thank you
Manoi.

Kassa,

You can see the duplicates by using the following query...

sql> select * from temp_rajesh;

      COL1       COL2 MESSAGE
---------- ---------- ------------------
       100        200 message
       100        200 message2
       300        400 message3
       400        500 message 4

sql> select col1, col2, count(*)
  2     from temp_rajesh
  3       group by col1, col2
  4         having count(*) > 1;

      COL1       COL2   COUNT(*)
---------- ---------- ----------
       100        200          2

-If in the case of duplicate records, you should see only the duplicates (according to some timestamp etc., you can use the functinon row_number analytic..)

  1  select col1, col2 from (
  2  select col1, col2,
  3         row_number() over (partition by col1, col2
  4                            order by message) rn
  5    from temp_rajesh)
  6*   where rn > 1
sql> /

      COL1       COL2
---------- ----------
       100        200

In the above example, I use message to order, you can replace it with activity_timestamp or the insertd_date according to your logic... when there are two records... one that you choose to duplicate.

Thank you
Rajesh.

Published by: Rajesh Chamarthi on November 20, 2009 12:05 AM (added for example)

Tags: Database

Similar Questions

  • How to delete records from a table?

    It comes to my table structure:
    create table BILLS
    (
      bill_id    VARCHAR2(20),
      trx_no     VARCHAR2(20),
      item_code  VARCHAR2(3),
      amount     NUMBER,
      item_id    NUMBER,
      invoice_dt DATE
    )
    Here are some insert statements to populate the table. *(About a 100 of them, please Bear with me) *.
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104173960', '910873', '002', 432, 351, to_date('04-03-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104209800', '910873', '002', 432, 351, to_date('04-04-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104212747', '263156', '039', 230, 351, to_date('01-04-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104269414', '263156', '039', 230, 351, to_date('01-06-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104360446', '263156', '039', 230, 351, to_date('01-09-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104577673', '910873', '002', 432, 351, to_date('04-04-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104608668', '910873', '002', 432, 351, to_date('04-05-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104611586', '263156', '039', 230, 351, to_date('01-05-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104642560', '910873', '002', 432, 351, to_date('04-06-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104699154', '910873', '002', 432, 351, to_date('04-08-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104820820', '263156', '039', 230, 351, to_date('01-12-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104826028', '910873', '002', 432, 351, to_date('04-12-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104850631', '910873', '002', 432, 351, to_date('04-01-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104885554', '263156', '039', 230, 351, to_date('01-02-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104926901', '910873', '002', 432, 351, to_date('04-03-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104936656', '263156', '', 15, 247, null);
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104996320', '263156', '039', 230, 351, to_date('01-05-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105030104', '263156', '039', 230, 351, to_date('01-06-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105176803', '910873', '002', 432, 351, to_date('04-10-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105217998', '910873', '002', 432, 351, to_date('04-11-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105253306', '263156', '039', 230, 351, to_date('01-12-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105280152', '263156', '039', 230, 351, to_date('01-01-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105318072', '910873', '002', 432, 351, to_date('04-02-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105449712', '910873', '002', 432, 351, to_date('04-06-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105579048', '910873', '002', 432, 351, to_date('04-10-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105611201', '263156', '039', 230, 351, to_date('01-11-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105679991', '263156', '011', 196.56, 351, to_date('06-01-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105686749', '910873', '002', 432, 351, to_date('04-01-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105816473', '910873', '002', 432, 351, to_date('04-05-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105846525', '263156', '011', 230, 351, to_date('01-06-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105778111', '910873', '002', 432, 351, to_date('04-04-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104958496', '910873', '002', 432, 351, to_date('04-04-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105143695', '910873', '002', 432, 351, to_date('04-09-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104176755', '263156', '039', 230, 351, to_date('01-03-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104365552', '910873', '002', 432, 351, to_date('04-09-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104646837', '263156', '039', 230, 351, to_date('01-06-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104763596', '910873', '002', 432, 351, to_date('04-10-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104936656', '263156', '', 15, 247, null);
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105510930', '263156', '039', 230, 351, to_date('01-08-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104302780', '263156', '039', 230, 351, to_date('01-07-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104793590', '263156', '039', 230, 351, to_date('01-11-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104238583', '910873', '002', 432, 351, to_date('04-05-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105779115', '263156', '011', 230, 351, to_date('01-04-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104394481', '263156', '039', 230, 351, to_date('01-10-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105144934', '263156', '039', 230, 351, to_date('01-09-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105342823', '263156', '039', 230, 351, to_date('01-03-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105747780', '910873', '002', 432, 351, to_date('04-03-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105517258', '910873', '002', 432, 351, to_date('04-08-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105617909', '910873', '002', 432, 351, to_date('04-11-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104480711', '910873', '002', 432, 351, to_date('04-01-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105845480', '910873', '002', 432, 351, to_date('04-06-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105349031', '910873', '002', 432, 351, to_date('04-03-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105382599', '263156', '039', 230, 351, to_date('01-04-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104423263', '263156', '039', 230, 351, to_date('01-11-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104482370', '263156', '039', 230, 351, to_date('01-01-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104892872', '910873', '002', 432, 351, to_date('04-02-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105071771', '263156', '039', 230, 351, to_date('01-07-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105716829', '910873', '002', 432, 351, to_date('04-02-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105251149', '910873', '002', 432, 351, to_date('04-12-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105420465', '910873', '002', 432, 351, to_date('04-05-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105547036', '910873', '002', 432, 351, to_date('04-09-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105450806', '263156', '039', 230, 351, to_date('01-06-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105178143', '263156', '039', 230, 351, to_date('01-10-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105648407', '910873', '002', 432, 351, to_date('04-12-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105718070', '263156', '011', 230, 351, to_date('01-02-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104735083', '910873', '002', 432, 351, to_date('04-09-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105748707', '263156', '011', 230, 351, to_date('01-03-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104570555', '263156', '039', 230, 351, to_date('01-04-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105480249', '910873', '002', 432, 351, to_date('04-07-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104799512', '910873', '002', 432, 351, to_date('04-11-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105036878', '910873', '002', 432, 351, to_date('04-06-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105413781', '263156', '039', 230, 351, to_date('01-05-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105548204', '263156', '039', 230, 351, to_date('01-09-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104510445', '910873', '002', 432, 351, to_date('04-02-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104545120', '263156', '039', 230, 351, to_date('01-03-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104700608', '263156', '039', 230, 351, to_date('01-08-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104765006', '263156', '039', 230, 351, to_date('01-10-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105111984', '910873', '002', 432, 351, to_date('04-08-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105310993', '263156', '039', 230, 351, to_date('01-02-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105481415', '263156', '039', 230, 351, to_date('01-07-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105210719', '263156', '039', 230, 351, to_date('01-11-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105809981', '263156', '011', 230, 351, to_date('01-05-2011', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104328833', '910873', '002', 432, 351, to_date('04-08-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104511904', '263156', '039', 230, 351, to_date('01-02-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105278905', '910873', '002', 432, 351, to_date('04-01-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104421567', '910873', '002', 432, 351, to_date('04-11-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104851866', '263156', '039', 230, 351, to_date('01-01-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105649424', '263156', '039', 230, 351, to_date('01-12-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104729022', '263156', '039', 230, 351, to_date('01-09-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105070358', '910873', '002', 432, 351, to_date('04-07-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104299829', '910873', '002', 432, 351, to_date('04-07-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104920099', '263156', '039', 230, 351, to_date('01-03-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104266551', '910873', '002', 432, 351, to_date('04-06-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104994904', '910873', '002', 432, 351, to_date('04-05-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104910999', '263156', '', 15, 247, null);
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104241418', '263156', '039', 230, 351, to_date('01-05-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104960203', '263156', '039', 230, 351, to_date('01-04-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105381371', '910873', '002', 432, 351, to_date('04-04-2010', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104542458', '910873', '002', 432, 351, to_date('04-03-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104670160', '910873', '002', 432, 351, to_date('04-07-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105105026', '263156', '039', 230, 351, to_date('01-08-2009', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104392347', '910873', '002', 432, 351, to_date('04-10-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104451005', '910873', '002', 432, 351, to_date('04-12-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104453960', '263156', '039', 230, 351, to_date('01-12-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104671563', '263156', '039', 230, 351, to_date('01-07-2008', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('104331181', '263156', '039', 230, 351, to_date('01-08-2007', 'dd-mm-yyyy'));
    
    insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT)
    values ('105580192', '263156', '039', 230, 351, to_date('01-10-2010', 'dd-mm-yyyy'));
    It comes to my select statement.
    SELECT 
           Trx_No,
           Item_Code,
           Amount,
           Item_Id,
           MAX(Invoice_Dt)
      FROM Bills
     GROUP BY 
              Trx_No,
              Item_Code,
              Amount,
              Item_Id
    I want to remove the lines that are extracted from my select statement. What is the best way to achieve this?

    SELECT query sets.

    She literally takes

    delete from bills
     where (Trx_No,Item_Code,Amount,Item_Id,Invoice_Dt) in (select Trx_No,Item_Code,Amount,Item_Id,MAX(Invoice_Dt)
                                                              FROM Bills
                                                             GROUP BY Trx_No,Item_Code,Amount,Item_Id
                                                           )
    

    Concerning

    Etbin

  • Delete query to delete records from multiple tables

    All,

    I need a delete query that will delete the records from the tables. Please see the structure of the table & below
    CREATE TABLE TEMP1 (ID NUMBER(10),NAME VARCHAR2(40),CLASS VARCHAR2(40),COLLEGE VARCHAR2(40));
    CREATE TABLE TEMP2 (ID NUMBER(10),CITY VARCHAR2(40),STATE(40));
    
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (1000,'SAM','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (2000,'RIO','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (3000,'CHRIS','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (4000,'ALEX','CS','UNIV_1');
    
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (1000,'Auburn','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (2000,'Ithaca','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (3000,'Mount Vernon','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (4000,'Port Jervis','NY');
    Now, I need to delete the records in these tables where the ID is '2000' by using a single delete query. Is this possible? This may be a newbie question. Help, please.

    "using a single request deletion. Is this possible?

    Nope.
    You can insert into multiple tables by using a single query, INSERT ALL job, but you cannot delete more than one table using a single query.

  • Delete records from a table of forms

    Oracle forms6i
    Hai All

    I use forms6i and my need is I have generated a forms and the output is displayed through tables and I need to delete all the records from the table of my forms when executing next time pls tell me

    Concerning

    Srikkanth.M

    Hello

    Please try something like that.

    Begin
    Delete From Master_Tbl Cascade;
    forms_ddl('Commit');
    End;
    

    Sarah

  • How replicates all records from one table to another table without using expdp, impdp

    Hi I have two database in a database, that I have a table called t1 and another base data, I have the second table .so, my first table have records, that I need to transfer all records second T2 without use of expdp and impdp in every 5 min... what I do

    ??

    The best solution for this scenario is to use Oracle Golden Gate

    However, it requires a license, and you must pay for it.

    If this is not possible, you can create a job scheduler that uses a link DB in order to reproduce the recordings of the target database, but it will take the entire table to the target database and then INSERT AS SELECT truncate the data of the entire table every time that the job is running (because you can't follow only the records that have been changed or modified).

    In addition, read here on the replication of data using materialized views.

  • Deleting records from a table and trying to retrieve those

    Hello
    is it possible to recover the table deleted after validation of the track file, if so how? Once again I have to synchronize back to the database once the table is retrieved.

    Reverse GoldenGate utility.

    details on this forum.
    Reverse GoldenGate utility
    Golden Gate can be a lever to make point in time recovery for MySql?

  • How to delete columns from a table

    Hello

    I have a 2D chart composed of 12 columns. I want to just use the first three columns within LabView. What is the best way to extract the data from these three columns?

    Greetings

    Kristoffer

    You can watch from two different angles:

    • You can remove the extra columns
    • You can keep only the fist three columns

    Would be easier to use "subset of the table" and select the first three columns. See photo.

    (This assumes you want the three columns as a 2D array. If you want in three tables 1 d, you would use 'index array' resized to three exits.)

  • Shutter button to copy records from one table to another;  ORA-04091:

    Hello

    I am trying to create a trigger that will move data from one table to the other.

    I have two tables (Trial1, Trial2) two of them contains the same attributes (code, c_index)

    I want to spend each new record inserted in (code Trial1) (code in Trial2)

    It's my trigger:
    Create or replace trigger trg_move_to_trial2
    After Insert on Trial1
    for each row
    Start
    insert into Trial2 (code)
    Select: new.code of Trial1;
    end;
    He compiled, but when I insert a new record (the code) in (Trial1), it shows this error:
    Error report:
    SQL error: ORA-04091: table STU101. TRIAL1 is changing, function of triggering/can not see
    ORA-06512: at "STU101. TRG_MOVE_TO_TRIAL2', line 3
    ORA-04088: error during execution of trigger ' STU101. TRG_MOVE_TO_TRIAL2'
    04091 00000 - "table %s.%s is changing, function of triggering/can not see.
    * Cause: A trigger (or plsql user-defined function that is referenced in)
    This statement) attempted to watch (or modify) a table that has been
    in the Middle being modified by the statement that shot.
    * Action: Rewrite the trigger (or function) so it does not read this table.
    I know matter what it means error, but I did not how to fix the error.

    ..................................................................................................

    I tried to change the (insert after on Trial1) before (insert on Trial1); It worked, but not in a good way. When I insert value in (code Trial1) new and refreshed Trial2 table, just as much as the records I have 2 test they will be duplicated. For example
    Trial2
    code
    111
    222
    333
    when I insert in Trial1
    Trial1
    code
    444
    Trial2 will be:
    code
    111
    222
    333
    444
    444
    444
    can you please tell me how to fix this?

    Kind regards

    Published by: 1002059 on April 23, 2013 17:36

    You should not select Trial1 - you already have data. Simply insert this value.

    Create or replace trigger trg_move_to_trial2
    After insert on Trial1
    for each row
    
    begin
    
    insert into Trial2 (code)
    values (:new.code);
    
    end; 
    

    Kind regards
    David

  • Delete records from sys.aud$ stored procedure

    We have a stored procedure that attempts to move the records from the table of sys.aud$ to a history table (in order to keep sys.aud$ to a more reasonable size, I guess - full disclosure, I have not written this proc). Base flow is:
    Select count (*) in the number of lines of sys.aud$
    If {(rowcount > 1000)
    copy all rows in sys.aud$ in the history table
    remove from sys.aud$
    }

    I says this proc used to work perfectly in a troubled past (I'm new on the client) but now has not worked for a while. When we try to compile the proc, we get the error
    "table or view does not exist", and the line is the "deletion of sys.aud$. The line "select count (*) from sys.aud$ ' seems to cause no problems, but the proc does not compile as is. If I comment out the line "remove from sys.aud$", however, the proc compiles very well.

    Confusingly, if I log in as the same account that owns this proc, I can run both the count (*) select from sys.aud$ AND remove clauses sys.aud$ with no complaint at all (by modifying slightly to work with 1 single record at a time, of course), but I can't seem the same to compile in a stored proc.

    I guess that it is related permissions? Can someone point me to the permissions of the owner needs to be able to remove from sys.aud$ in a stored procedure? Or is there something else that needs to be done here? Pointers much appreciated.

    Thank you.

    956928 wrote:
    We have a stored procedure that attempts to move the records from the table of sys.aud$ to a history table (in order to keep sys.aud$ to a more reasonable size, I guess - full disclosure, I have not written this proc). Base flow is:
    Select count (*) in the number of lines of sys.aud$
    If (rowcount 1000 >) {}
    copy all rows in sys.aud$ in the history table
    remove from sys.aud$
    }

    I says this proc used to work perfectly in a troubled past (I'm new on the client) but now has not worked for a while. When we try to compile the proc, we get the error
    "table or view does not exist", and the line is the "deletion of sys.aud$. The line "select count (*) from sys.aud$ ' seems to cause no problems, but the proc does not compile as is. If I comment out the line "remove from sys.aud$", however, the proc compiles very well.

    Confusingly, if I log in as the same account that owns this proc, I can run both the count (*) select from sys.aud$ AND remove clauses sys.aud$ with no complaint at all (by modifying slightly to work with 1 single record at a time, of course), but I can't seem the same to compile in a stored proc.

    I guess that it is related permissions? Can someone point me to the permissions of the owner needs to be able to remove from sys.aud$ in a stored procedure? Or is there something else that needs to be done here? Pointers much appreciated.

    Thank you.

    acquired through ROLE privileges are NOT applicable within the named PL/SQL procedures.

    GRANT DELETE ON SYS. AUD$ ;

  • How to delete photos from my i phone 6 but keep them on my i mac

    How to delete photos from my i phone 6 but keep them on my i mac os x

    peterfromcredin wrote:

    How to delete photos from my i phone 6 but keep them on my i mac os x

    And how does your photos get your iMac?

    Photo stream that you use?

  • How to delete items from a cluster?

    Hello. I would like to know how to delete items from a cluster. I'm stuck with this problem. It has its own order of each element in a cluster. I tried to open a table, but it seems too complicated. In the attachment, I want to only get the data of 'flow' not 'pressure '. I try to use array programming, but it does not work. Would be nice if you help me to fix the file. Thank you

    Thank you very much. Your solution is way better than my confusing file.

  • How to remove photos from a mac that I get rid of without losing these photos on devices that I keep

    How to remove photos from a mac that I get rid of without losing these photos on devices that I keep

    Do not use iCLoud photo library - when you make any changes on any device are made on all devices

    LN

  • homegroup - I can't delete files from my laptop that I sent to her from my pc via homegroup.

    I can't delete files from my laptop that I sent to her from my pc via homegroup. Why? If I modify or delete a file on a pc will also be edit/delete on the other? (I want everything on my laptop I want on my desktop) I have the permissions on the desktop to read/write.

    Hello

    Remember that this is the reason for having a SHARED NETWORK... you share all. If you and I are working on a project that is shared on the network, we could work on and update the project. If you don't want this to be the case, do not share some files on the network. In other words, if I don't want then it in my music, I do not share my music directory.

    Happy computing,

    B Eddie

  • help in registration of the records from two tables

    HI: I have two tables joined the first field. The field is the primary key in the first table. Need help listing records from both tables with each a line/record results.
    create table EVENTS (
    event_key varchar2(64) primary key,
    event_description varchar2(64),
    create_time int
    );
    
    
    create table EVENT_UPDATES (
    event_key varchar2(64) NOT NULL ,
    update_description varchar2(64),
    update_time int
    );
    
    
    insert into EVENTS values('Event1', 'This is event1', 1);
    insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
    insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
    insert into EVENTS values('Event2', 'This is event2', 4);
    insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
    insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);
    I want to print each record in the table of EVENTS such as a line and the corresponding records in EVENT_UPDATES as a line like this record
    Event1   1     This is event1
                3     Ticket created
                10   Event cleared
    Event2   4     This is event2
                6     Ticket created
                8     Event cleared
    TIA
    Ravi
    select  case weight
              when 1 then event_key
            end key,
            time_val,
            description
      from  (
              select  event_key,
                      create_time time_val,
                      event_description description,
                      1 weight
                from  events
             union all
              select  event_key,
                      update_time,
                      update_description,
                      2 weight
                from  event_updates
            )
      order by event_key,
               weight
    /
    
    KEY          TIME_VAL DESCRIPTION
    ---------- ---------- -------------------------
    Event1              1 This is event1
                        3 Ticket created
                       10 Event cleared
    Event2              4 This is event2
                        6 Ticket created
                        8 Event cleared
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • The use of sequence and generate the number in a table that has data

    Hello

    There is a custom table that has a column Rowid (NULL).
    This table already has 10 k with rowid as null lines, now the user asks me to enter a unique number for the Rowid.
    I created a sequence, but don't know how to use this sequence and generate numbers for the Rowid.

    Could you suggest.

    Thank you.

    "rowid" is an oracle reserved word and should be avoided. Perhaps "Rowid" between quotes or something.

    Here's how to "fill" a column by a sequence:

    SQL> create table t (id number, value varchar2(100));
    
    Table created.
    
    SQL> insert into t (value) select object_name from all_objects where rownum <= 10000;
    
    10000 rows created.
    
    SQL> create sequence idgen_sequence;
    
    Sequence created.
    
    SQL> update t set id = idgen_sequence.nextval;
    
    10000 rows updated.
    

    Given that the sequence was used all the 'id's will be unique.

Maybe you are looking for

  • MacBook Air (2015) randomly freezes on me?

    My MacBook Air (2015) will freeze randomly on me unexpectedly. I noticed that it was mainly when I use Safari. Y at - it a bug in the computer or in Safari? All suggestions are welcome!

  • Presario CQ57: administrator password

    Compaq Presario CQ57 asks password administrator and displays "system disabled" after three trials, and it shows the code number 52378963

  • Help, please! my Eee netbook will not start!

    Hello My Eee netbook (Windows xp) does not start I tried to start in safe mode, but it hangs just for 'isapnp.sys '. It seems that I imported a virus on my system. I can't perform an installation as netbook is not a hard drive. What can I do? (I use

  • Is it possible to close all open easily programs?

    original title: IS THERE A SHORT CUT 2 CLOSE all OPEN FILES? __ MY COMPUTOR SAYS THAT I NEED TO CLOSE ALL OPEN FILES AS IM OUT OF MEMORY... IS THERE A SHORTCUT TO DO THIS OR CAN SOMEONE HELP ME AS IM NEW TO A PAOLO THANX.

  • WINDOWS NOT RESERVED 10 BUT ME TOLD TO UPGRADE NOW (2,092.5 MB) AS ITS BASE ON MY LAPTOP

    1. I do not wish to BOOK my Upgade until closer to the date of end of July 2016 free offer 2. I have NOT activated the Windows 10 RESERVE sitting in the lower bottom of HR near my clock APP. 3. when I activate my normal 7 Windows updates, Windows 10