好的,抱歉,如果这是转贴,我真的不知道如何表达我正在寻找的内容才能真正搜索它。
我有 3 个表:
Amenities:
AmenitiesID
Name
resort_amenities
ResortAmenitiesID
ResortID
AmenityID
resorts
ResortID
ResortName
and so on...
我正在编写将 amenties 链接到度假村的代码,并保存在 resort_amenities 中。
我想要的是让一个 jQuery 模态对话框显示便利设施表中尚未链接到该度假村的所有便利设施。
现在在我的 ajax 调用中,我传递了度假村 ID,以便在某处的 sql 中使用。
我相信我需要一个工会,但几年前从未在校外建立过工会。
谢谢
最佳答案
因此,对于特定度假村,您需要与该度假村无关的一系列便利设施:
SELECT DISTINCT * -- get all those Amenities
FROM Amenities
WHERE NOT EXISTS ( -- that we can't find a counter-example for
SELECT AmenitiesID
From resort_amenities
WHERE ResortID = <the resort id>
AND Amenities.AmenitiesID = resort_amenities.AmenitiesID
)
这是一个集合减法,S = S1 - S2
,其中 S1
是所有设施的集合,S2
是已与该度假村相关联的一系列便利设施。
关于MySQL 选择与某条记录无关的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959349/