I am after an SQL command to find units with no categories. Here are the tables:
Unit
id name
U开发者_如何学JAVAnitCategory
id name
UnitCategoryIndex
id categoryid unitid
Thanks!
Double check the syntax (i wrote it for 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
)
精彩评论