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 MILL%' ORDER BY sellDate DESC' at line 1SELECT count(*) total FROM history WHERE sellDate < '2016-08-23' and sellDate > '1969-11-30' and streetNumber=1425 and REPLACE(streetName,'\'','') like '%LAMEY'S MILL%' ORDER BY sellDate DESC