开发者

Find units with zero categories

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
                  )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜