André Santos André Santos - 25 days ago 5
SQL Question

Delete multiple rows in sql

I Have two tables like this

table L

- A | B

- C | D

  • table K

    A | B

    C | D

    E | F
    etc etc

I whish to delete in table K all the lines that exist in Table L. However when I do delete it will only eliminate the first line. I would like that if more lines where inserted into L that coincide with lines in K the delete would work as well, this is, not having to do a "manual" delete
Thanks in advance


You can use delete with an alias and an existential quantifier to accomplish that:

delete k
from K as k
where exists (
    select * from L as l
    where l.col1=k.col1 and l.col2=k.col2