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 '238) and (((inv.state= 1 and now() > (inv.start_date) and (now() < (' at line 31 SQL=select slec.*, mainCategory, mainCategoryId, categoryMaker, companyName, features, GREATEST(if(FIND_IN_SET('featured_companies',features) ,1,0), featured) as featured from ( select as companyName, as companyId1,,, cp.alias, cp.short_description, cp.meta_description, cp.street_number, cp.address,, cp.county, cp.province, cp.area,,,,, cp.state, cp.fax, cp.averageRating, cp.slogan,cp.logoLocation, cp.activity_radius, cp. review_score, cp.creationDate, cp.featured,cp.publish_only_city,cp.userId, cp.latitude, cp.longitude, cp.keywords,cp.approved, cp.mainSubcategory, cp.countryId,cp.typeId, cp.postalCode, cp.publish_start_date, cp.publish_end_date, GROUP_CONCAT( DISTINCT,'|',,'|',cg.alias ORDER BY separator '#|') as categories, GROUP_CONCAT( DISTINCT as categoryIds, as mainCategory, bcm.alias as mainCategoryAlias ,bcm.markerLocation as categoryMaker, as mainCategoryId, as typeName, #cnt.contact_name, count(distinct as nrRatings, GROUP_CONCAT(DISTINCT pf.feature) as features, max(p.ordering) as packageOrder from #__jbusinessdirectory_companies cp left join #__jbusinessdirectory_company_category cc on left join #__jbusinessdirectory_categories cg on and cg.published=1 left join #__jbusinessdirectory_categories bcm on and bcm.published=1 #left join #__jbusinessdirectory_company_contact cnt on left join #__jbusinessdirectory_company_types ct on left join #__jbusinessdirectory_orders inv on left join #__jbusinessdirectory_packages p on ( and p.status=1 and 1) or (p.price=0 and p.status=1 and 1) left join #__jbusinessdirectory_package_fields pf on left join #__jbusinessdirectory_company_ratings cra on where 1 and cp.state=1 and cc.categoryId in (,238) and (((inv.state= 1 and now() > (inv.start_date) and (now() < (inv.start_date + INTERVAL p.days DAY) or ( and p.days = 0)))) or p.price=0) and (cp.approved = 2 or cp.approved= -1 or cp.approved= 0) and (cp.publish_start_date<=DATE(now()) or cp.publish_start_date='0000-00-00' or cp.publish_start_date is null) and (cp.publish_end_date>=DATE(now()) or cp.publish_end_date='0000-00-00' or cp.publish_end_date is null) group by ) as slec where 1 having 1 order by featured desc, companyName LIMIT 0, 50