groupid NOT IN (SELECT id FROM groups) groupid NOT IN (SELECT id FROM (SELECT DISTINCT id FROM groups) AS groups_ids)