You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND contributors_images.image_id IS NOT NULL ORDER BY `primary` DESC, contribu' at line 11 ==> SELECT `contributors_events`.`event_id`, `images`.`id`, `images`.`filename`, `images`.`caption`, `images`.`alt`, `images`.`width