select a.id, a.title, a.body, a.projectidfk, a.useridfk, a.posted, p.name as project, u.name as author from (lh_announcements a left join lh_projects p on a.projectidfk = p.id) left join lh_users u on a.useridfk = u.id where 1=1 and (a.projectidfk in () or a.projectidfk = '' ) order by p.name asc, a.posted desc