SQL: Remove specific records from one table based on records present in another table.

Tags:
PL/SQL
SQL
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.

Software/Hardware used:
Sql, plsql

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    It is possible to find duplicate records using either distinct or row number or group by approach. in which group by is a better approach. However assuming this is your course related or something like that, now you can use this hints to learn more.
    93,430 pointsBadges:
    report
  • ToddN2000
    Post your code so far and we can help you with any mistakes. It takes time to learn SQL but if we do the work it will just take you longer to learn the basics.
    89,235 pointsBadges:
    report
  • carlosdl
    You could also use an EXISTS condition with a subquery.  Depending on the size of the tables there are other more complex methods, that could be more efficient.

    As suggested by others, let us see what you have tried, and we will help you out.
    84,355 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: