Solved

Delete from a table using a multi column primary key

Posted on 2011-02-11
2
409 Views
Last Modified: 2012-08-14
I can efficiently select the multi column key to delete from my target table and I'm curious if a merge is the most efficient way to execute this delete...

PK on MYTABLE_2 is MYTABLE_2_Key.
PK on MYTABLE_3 is MYTABLE_3_Key.
PK on MYTABLE_2_3_XREF is MYTABLE_2_Key, MYTABLE_3_Key

MERGE INTO MYTABLE_2_3_XREF T1 USING(
SELECT T1.MYTABLE_2_Key, T2.MYTABLE_3_Key
FROM (SELECT Key_Col_1
  FROM MYTABLE_2
  WHERE MYTABLE_2_Key in (1,2,3)) T1,
(SELECT KEY_COL_2
  FROM MYTABLE_3
  WHERE MYTABLE_3_Key IN (4,5,6)) T2
) T2
ON (T1.MYTABLE_2_Key=T2.MYTABLE_2_Key AND
T1.MYTABLE_3_Key=T2.MYTABLE_3_Key)
WHEN MATCHED THEN UPDATE SET INSERT_DTM=SYSDATE
Delete WHERE (1=1);
0
Comment
Question by:gswitz
2 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34875102
you can delete first then run update instead of merge

delete from mytable
where (col1,col2) in (select col1,col2 from mytable2);

then write update or merge query...
0
 

Author Closing Comment

by:gswitz
ID: 34883244
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question