select distinct oc.objectId,
(select count(*) from object_categories oc2
join devices_categories dc2 on oc2.categoryId = dc2.deviceCat
where dc2.deviceId = 1 and oc2.objectId=oc.objectId ) v1,
(select count(*) from devices_categories dc3 where dc3.deviceId = 1) v2
from object_categories oc
where v1 = v2;
#define YYCTYPE unsigned char