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 'ERROR: SELECT COUNT(DISTINCT p.productID) FROM ?#PRODUCTS_TABLE p where catego' at line 1 SQL query : ERROR: SELECT COUNT(DISTINCT p.productID) FROM ?#PRODUCTS_TABLE p where categoryID>1 and enabled=1 and ( LOWER(name) LIKE '%cortland%' OR LOWER(product_code) LIKE '%cortland%' OR LOWER(mas_id) LIKE '%cortland%' OR LOWER(nametype) LIKE '%cortland%' OR LOWER(comp) LIKE '%cortland%' OR LOWER(contry) LIKE '%cortland%' OR LOWER(productID) LIKE '%cortland%' ) AND ( LOWER(name) LIKE '%tab%' OR LOWER(product_code) LIKE '%tab%' OR LOWER(mas_id) LIKE '%tab%' OR LOWER(nametype) LIKE '%tab%' OR LOWER(comp) LIKE '%tab%' OR LOWER(contry) LIKE '%tab%' OR LOWER(productID) LIKE '%tab%' ) AND ( LOWER(name) LIKE '%001%' OR LOWER(product_code) LIKE '%001%' OR LOWER(mas_id) LIKE '%001%' OR LOWER(nametype) LIKE '%001%' OR LOWER(comp) LIKE '%001%' OR LOWER(contry) LIKE '%001%' OR LOWER(productID) LIKE '%001%' ) AND ( LOWER(name) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(product_code) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(mas_id) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(nametype) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(comp) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(contry) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' OR LOWER(productID) LIKE '%iUNKNOWN_PLACEHOLDER_ioeaea%' )