我有一个可以取得一些结果的工作查询。
$sql = "
SELECT
swdl.wedding_dress AS wedding_dress,
wd.name AS name,
wdi.url AS image
FROM salons_wedding_dresses_link AS swdl
LEFT JOIN wedding_dresses AS wd ON swdl.wedding_dress = wd.id
LEFT JOIN wedding_dress_images AS wdi ON wdi.wedding_dress = wd.id AND wdi.main_image = 1
WHERE swdl.salon = ? AND wd.active = 1
";
我想要的是将其更新为只获取表wedding_dress
中的salons_wedding_dresses_link
不在wedding_dress_dress_collection_link
列中的wedding_dress_id
表中但我没有这样做的结果。
Bellow是更新的查询,更新为粗体。
$sql = "
SELECT
swdl.wedding_dress AS wedding_dress,
wd.name AS name,
wdi.url AS image
FROM salons_wedding_dresses_link AS swdl
LEFT JOIN wedding_dress_dress_collection_link AS wddcl
------------------------------------------------------
LEFT JOIN wedding_dresses AS wd ON swdl.wedding_dress = wd.id
LEFT JOIN wedding_dress_images AS wdi ON wdi.wedding_dress = wd.id AND wdi.main_image = 1
WHERE
swdl.wedding_dress NOT IN (SELECT wddcl.wedding_dress_id FROM wddcl) AND
------------------------------------------------------------------------
swdl.salon = ? AND wd.active = 1
";
答案 0 :(得分:0)
选择查询以获取salons_wedding_dresses_link
但不在wedding_dress_dress_collection_link
中的结果:
select s1.*,s2.wedding_dress_collection_id,s2.wedding_dress_id
from salons_wedding_dresses_link s1
left join wedding_dress_dress_collection_link s2 on
s1.wedding_dress=s2.wedding_dress_id
whrere s2.wedding_dress_id is null;