You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'S MILL%' ORDER BY sellDate DESC' at line 1SELECT count(*) total FROM history WHERE sellDate < '2018-06-21' and sellDate > '1969-11-30' and streetNumber=1425 and REPLACE(streetName,'\'','') like '%LAMEY'S MILL%' ORDER BY sellDate DESC