Skip to content

Instantly share code, notes, and snippets.

@cohan
Created November 22, 2012 13:14
Show Gist options
  • Save cohan/4131121 to your computer and use it in GitHub Desktop.
Save cohan/4131121 to your computer and use it in GitHub Desktop.
Zabbix (1.8) - MySQL query to select hosts NOT IN a specific group
# Not in a single group:
SELECT host FROM hosts h
WHERE NOT EXISTS
(SELECT groupid FROM hosts_groups hg
WHERE h.hostid = hg.hostid
AND hg.groupid = 100100000000001);
# Not in multiple groups:
SELECT host FROM hosts h
WHERE NOT EXISTS
(SELECT groupid FROM hosts_groups hg
WHERE h.hostid = hg.hostid
AND hg.groupid IN (100100000000001,100100000000002,100100000000003,100100000000004,100100000000005) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment