Cannot perform query. 1064 : 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 _tours.active = '1' AND _tours.tour_id NOT IN (0) AND _tours.property_sold =' at line 45 SELECT * FROM (SELECT _tours.tour_id, _tours.distributor_id, _tours.member_id, _tours.title, _tours.address, _tours.city, _tours.state_id, _tours.country_id, _tours.zip_code, _tours.property_sold, _tours.property_sold_date, _tours.price, _tours.property_type_id, _tours.property_style_id, _tours.bedrooms, _tours.baths, _tours.mls, _tours.mls_link, _tours.mls_description, _tours.submit_date, _tours.active, _tours.expiration_date, _tours.update_time, _tours.test_mode, _tours.music, _tours.music_id, '' AS type, local_listings.new_color_id, local_listings.new_order_by, local_listings.new_order_by_sold, member.share_type, distributor_profile.distributor_id AS affiliate_id, vt_property_type.property_type_name AS property_type_name, vt_property_style.property_style_name AS property_style_name, vt_property_style.property_style_sua AS property_style_sua FROM _tours LEFT JOIN vt_property_type ON _tours.property_type_id = vt_property_type.property_type_id LEFT JOIN vt_property_style ON _tours.property_style_id = vt_property_style.property_style_id LEFT JOIN distributor_profile ON _tours.distributor_id = distributor_profile.distributor_id LEFT JOIN local_listings ON local_listings.member_id = _tours.member_id AND local_listings.has_affiliate = '0' LEFT JOIN member ON member.member_id = _tours.member_id WHERE AND _tours.active = '1' AND _tours.tour_id NOT IN (0) AND _tours.property_sold = '0' ORDER BY submit_date desc ) member_active UNION ALL SELECT * FROM (SELECT _tours.tour_id, _tours.distributor_id, _tours.member_id, _tours.title, _tours.address, _tours.city, _tours.state_id, _tours.country_id, _tours.zip_code, _tours.property_sold, _tours.property_sold_date, _tours.price, _tours.property_type_id, _tours.property_style_id, _tours.bedrooms, _tours.baths, _tours.mls, _tours.mls_link, _tours.mls_description, _tours.submit_date, _tours.active, _tours.expiration_date, _tours.update_time, _tours.test_mode, _tours.music, _tours.music_id, '' AS type, local_listings.new_color_id, local_listings.new_order_by, local_listings.new_order_by_sold, member.share_type, distributor_profile.distributor_id AS affiliate_id, vt_property_type.property_type_name AS property_type_name, vt_property_style.property_style_name AS property_style_name, vt_property_style.property_style_sua AS property_style_sua FROM _tours LEFT JOIN vt_property_type ON _tours.property_type_id = vt_property_type.property_type_id LEFT JOIN vt_property_style ON _tours.property_style_id = vt_property_style.property_style_id LEFT JOIN distributor_profile ON _tours.distributor_id = distributor_profile.distributor_id LEFT JOIN local_listings ON local_listings.member_id = _tours.member_id AND local_listings.has_affiliate = '0' LEFT JOIN member ON member.member_id = _tours.member_id WHERE AND _tours.active = '1' AND _tours.tour_id NOT IN (0) AND _tours.property_sold = '1' ORDER BY submit_date desc ) member_sold LIMIT 0,6