![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
delete table_1 where table_1.field1 in (select table_2.field1 from table_2 )and table_1.field2 in (select table_2.field2 from table_2) |
#2
| |||
| |||
|
|
Hello. I'm moving over from Sybase, and am looking for the equivalent syntax to the following command: delete table_1 from table_1, table_2 where table_1.field1 = table_2.field1 and table_1.field2 = table_2.field2 In other words delete, only from table_1, anything where field1 and field2 match a row in table_2. Any ideas? |
#3
| |||
| |||
|
|
SQL> delete t1 2 where exists ( 3 select null from t2 4 where t1.id=t2.id 5 and t1.col2=t2.col2); |
#4
| |||
| |||
|
|
Niall Litchfield wrote: SQL> delete t1 2 where exists ( 3 select null from t2 4 where t1.id=t2.id 5 and t1.col2=t2.col2); I was just about to post an answer with that version of the delete statement as well :-) I would think that this is more efficient then having two subselects. |
#5
| |||
| |||
|
|
"Thomas Kellerer" <spam_eater (AT) gmx (DOT) net> wrote in message news:bf6f1v$beoqf$1 (AT) ID-13919 (DOT) news.uni-berlin.de... Niall Litchfield wrote: SQL> delete t1 2 where exists ( 3 select null from t2 4 where t1.id=t2.id 5 and t1.col2=t2.col2); I was just about to post an answer with that version of the delete statement as well :-) I would think that this is more efficient then having two subselects. I *believe* that deleting from a view would be yet more efficient, but implies that the base tables need primary keys. -- Niall Litchfield Oracle DBA Audit Commission UK ***************************************** Please include version and platform and SQL where applicable It makes life easier and increases the likelihood of a good answer ****************************************** |
#6
| |||
| |||
|
|
JJ Reynolds schrieb: or.. an even cuter syntax! delete from t1 where (col1, col2) in (select col1, col2 from t2); This is cool ![]() I didn't know that this is possible. After so many years of SQL experience one can still learn new things.. Cheers Thomas |
#7
| |||
| |||
|
|
It's recent.. I know it works in 9i, but not sure about 8i (don't have an 8i instance to try it on). It absolutely did not work in 7.x. "Thomas Kellerer" <spam_eater (AT) gmx (DOT) net> wrote in message news:bf9cia$8rs$1 (AT) svr8 (DOT) m-online.net... JJ Reynolds schrieb: or.. an even cuter syntax! delete from t1 where (col1, col2) in (select col1, col2 from t2); This is cool ![]() I didn't know that this is possible. After so many years of SQL experience one can still learn new things.. Cheers Thomas |
![]() |
| Thread Tools | |
| Display Modes | |
| |