我在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