I believe it should have:
+ "and gaa.owner_group_id is not null "
instead of:
+ "and gaa.owner_group_id is null "