我正在尝试从数据库中获取行,其中id不等于从链接表返回id。可以使用连接完成吗?
select *
from module_items_profile people
where people.item_id not in (
select link.people_id
from link_page_people link
where link.page_id = $page_id
)
答案 0 :(得分:0)
是的,但使用带有LEFT JOIN
谓词的IS NULL
:
select *
from module_items_profile AS people
LEFT JOIN
(
SELECT *
FROM link_page_people
where page_id = $page_id
) AS link ON people.item_id = link.people_id
WHERE link.people_id IS NULL;