开发者

Find units with zero categories

开发者 https://www.devze.com 2023-01-01 14:15 出处:网络
I am after an SQL command to find units with no categories. Here are the tables: Unit idname U开发者_如何学JAVAnitCategory

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

精彩评论

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