tags:

views:

35

answers:

3

Hello,

I am after an SQL command to find units with no categories. Here are the tables:

Unit

id  name

UnitCategory

id  name

UnitCategoryIndex

id  categoryid  unitid

Thanks!

+1  A: 
SELECT id FROM Unit WHERE NOT EXISTS (SELECT 1 FROM UnitCategoryIndex WHERE Unit.id = UnitCategoryIndex.unitid)
Tesserex
+1  A: 
select *
  from unit U
 where not exists ( select *
                      from unitcategoryindex X
                     where X.unitid = U.id
                  )
Mark Baker
+3  A: 

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
Abe Miessler
Works great, thanks Abe
Kevin Sedgley