First of all, I don't know if the title is right but let me show you what I want and I will correct it as suggested. So, I have 2 tables:
- table1
- ID, subid, name
- table2
- ID
What I want is to delete any element from table2
that has ID
equal to subid
in table1
, where table1.name
is equal to a specified value.
If I have these elements in table1
ID subid name
1 ... 1 ...... name1
2 ... 3 ...... name2
3 ... 2 ...... name1
4 ... 1 ...... name2
and these rows in table2
ID
1
2
3
4
I would like to remove those elements in table2
with ID = subid, when name = name1, which means elements 1 and 2.
Something like:
DELETE FROM table2
WHERE ID = (SELECT subid
FROM table1
WHERE NAME = "name1")
Is this possible?