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 (listings.type = 6) AND listings.Status != 5 GROUP BY listings.ListID ORDER ' at line 1 SELECT listings.ListID FROM listings LEFT JOIN lodgings_meta ON (listings.ListID = lodgings_meta.ListID) WHERE listings.LocID = AND (listings.type = 6) AND listings.Status != 5 GROUP BY listings.ListID ORDER BY listings.Names ASC