【发布时间】:2010-08-27 13:15:45
【问题描述】:
我有 2 张桌子:Contacts 和 Users。
Contacts 表包含user_id,它们引用Users 表中的id。 Contacts 还包含list_type 列。
Contacts: user_id, list_type
Users: id, data
如何从两个表(Contacts 和 Users)中删除引用给定 list_type 的条目/行?
诀窍是我不想删除属于其他联系人list_type的users。
编辑:
例子:
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
现在我想删除list_type = 2,结果应该是:
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
【问题讨论】: