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 's_Cross.html%' OR `guild_property`.`portal_property_residential_sales`.`property' at line 5 SELECT `guild_property`.`portal_property_residential_sales`.`propertyID` FROM `guild_property`.`portal_property_residential_sales` WHERE (`guild_property`.`portal_property_residential_sales`.`referenceNumber` LIKE '%King's_Cross.html%' OR `guild_property`.`portal_property_residential_sales`.`propertyID` = 0) AND propertyActive = 'Active' UNION ALL SELECT `guild_property`.`portal_property_residential_lettings`.`propertyID` FROM `guild_property`.`portal_property_residential_lettings` WHERE (`guild_property`.`portal_property_residential_lettings`.`referenceNumber` LIKE '%King's_Cross.html%' OR `guild_property`.`portal_property_residential_lettings`.`propertyID` = 0) AND propertyActive = 'Active'