SELECT
objectId
FROM
objects
WHERE objectId NOT IN
(SELECT
objectId
FROM
objects_categories
WHERE
objectCat NOT IN (
select
deviceCat
FROM
device_categories
WHERE
deviceId=1
)
)
select o.objectId from objects o
where not exists (
select * from
object_category oc
join device_category dc on oc.categoryId = dc.deviceCat
where dc.deviceId = 1
and o.objectId = oc.objectId
)
select
deviceCat
FROM
device_categories
WHERE
deviceId=1
SELECT
objectId
FROM
objects_categories
WHERE
objectCat NOT IN (1,2,4,5,7,8)