我正在使用SQL命令查找没有类别的单元。以下是表格:
单元
id name
UnitCategory
id name
UnitCategoryIndex
id categoryid unitid
谢谢!
答案 0 :(得分:3)
仔细检查语法(我为SQL Server编写)。
SELECT u.id, u.name
FROM Unit as u
LEFT JOIN UnitCategoryIndex as uci
ON u.id = uci.UnitId
where uci.id is null
答案 1 :(得分:1)
SELECT id FROM Unit WHERE NOT EXISTS (SELECT 1 FROM UnitCategoryIndex WHERE Unit.id = UnitCategoryIndex.unitid)
答案 2 :(得分:1)
select *
from unit U
where not exists ( select *
from unitcategoryindex X
where X.unitid = U.id
)