我在SQL命令之后查找没有类别的单位。下面是表:查找具有零类别的单位
单位
id name
UnitCategory
id name
UnitCategoryIndex
id categoryid unitid
ŧ汉克斯!
我在SQL命令之后查找没有类别的单位。下面是表:查找具有零类别的单位
单位
id name
UnitCategory
id name
UnitCategoryIndex
id categoryid unitid
ŧ汉克斯!
仔细检查语法(我写它的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
SELECT id FROM Unit WHERE NOT EXISTS (SELECT 1 FROM UnitCategoryIndex WHERE Unit.id = UnitCategoryIndex.unitid)
select *
from unit U
where not exists (select *
from unitcategoryindex X
where X.unitid = U.id
)
工程很好,谢谢安倍 – 2010-06-01 15:31:55