question

Raghvendra2512 avatar image
Raghvendra2512 asked

How to remove records from one table based on records present in another table?

Suppose we have two tables T1 and T2 as described below: T1:- Col 1 Col2 Valid 1 a 120 2 b 232 1 b 435 3 a 123 2 c 532 T2:- Col 1 Col2 Invalid 1 a 1133 2 b 2321 2 a 4234 Now what can be the simplest query to remove all the records from T1 which are also present in T2 having the same values of both the columns Col1 and Col2. For example 1-a combination is present in T2 so it should be removed from T1 whereas 1-b should not be removed from T1.
sqlplsqlinterview-questions
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
schindam26 avatar image
schindam26 answered
Below code will help you DELETE T1 FROM T1 INNER JOIN T2 ON T1.Col1 = T2.Col1 AND T1.Col2 = T2.Col2
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.