I have got 2 tables: Contacts and Users.
Contacts table contains user_id which are referring to id in Users table. Contacts also contain list_type column.
Contacts: user_id, list_type
Users: id, data
How can I delete entries/rows from both tables (Contacts and Users) that are referring to given list_type?
The trick is that i don't want to delete users who belongs to other contacts list_type.
EDIT:
Example:
Users (id,data)
1 John
2 Kate
3 Alan
4 Bob
Contacts (user_id, list_type)
1 1
3 1
1 2
4 2
2 2
Now I would like to delete list_type = 2, the result should be:
Users (id,data)
1 John - still is here, because it was also referring to list_type = 1
3 Alan
Contacts (user_id, list_type)
1 1
3 1