Invalid SQL: select *,items.id as tid,items.description as description ,count(*) as numitems from kingdomappsNEW_items as items inner join kingdomappsNEW_customfeat as customfeat on (items.id = customfeat.itemid and ( ) and customfeat.active=1 )where items.active=1 and items.stockcount>0 and (catID=51 or items.catID in (52,54,55,53)) group by itemid having numitems > order by CAST(items.price AS UNSIGNED)