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 '%aaoaUNKNOWN_PLACEHOLDER_ay%' OR LOWER(product_code ) LIKE '%aaoaUNKNOWN_PLACEHOLDER_ay%' OR LOWER(brief_description) LIKE '%aaoaUNKNOWN_PLACEHOLDER_ay%' ) AND ( LOWER(name) LIKE '%nokia%' OR LOWER(product_code ) LIKE '%nokia%' OR LOWER(brief_description) LIKE '%nokia%' ) AND ( LOWER(name) LIKE '%lumia%' OR LOWER(product_code ) LIKE '%lumia%' OR LOWER(brief_description) LIKE '%lumia%' ) AND ( LOWER(name) LIKE '%920%' OR LOWER(product_code ) LIKE '%920%' OR LOWER(brief_description) LIKE '%920%' ) AND ( LOWER(name) LIKE '%or%' OR LOWER(product_code ) LIKE '%or%' OR LOWER(brief_description) LIKE '%or%' ) AND ( LOWER(name) LIKE '%1=''0=a%' OR LOWER(product_code ) LIKE '%1=''0=a%' OR LOWER(brief_description) LIKE '%1=''0=a%' ) AND ( LOWER(name) LIKE '%and%' OR LOWER(product_code ) LIKE '%and%' OR LOWER(brief_description) LIKE '%and%' ) AND ( LOWER(name) LIKE '%1=1%' OR LOWER(product_code ) LIKE '%1=1%' OR LOWER(brief_description) LIKE '%1=1%' )