Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - how to delete from one table while referring fom other table?

Tags:

sql

how can i delete from table A while comparing two fields A.P and A.C to table B's B.P and B.C while looking for all matches of B.R = 1 ?

actually neither of the following work but it should go into the direction, unfortunately i can't figure out how...

DELETE FROM A WHERE (A.P = B.P AND A.C = B.C where B.C = 1)

DELETE FROM A WHERE (SELECT B.P, B.C FROM B WHERE B = 1)
like image 746
mgmx Avatar asked Jan 22 '10 16:01

mgmx


1 Answers

DELETE FROM A
FROM A INNER JOIN B ON A.P = B.P AND A.C = B.C
WHERE B.C = 1

The double FROM sometimes throws people off.

like image 183
womp Avatar answered Oct 21 '22 16:10

womp