SQL=select slec.*, mainCategory, mainCategoryId, categoryMaker, companyName, companyId1, count(cra.id) as nrRatings, features, GREATEST(if(FIND_IN_SET('featured_companies',features) ,1,0), featured) as featured from ( select cp.*, cp.name as companyName,cp.id as companyId1, ct.name as typeName, #cnt.contact_name, GROUP_CONCAT(DISTINCT pf.feature) as features, max(p.ordering) as packageOrder, bc.name as mainCategory, bc.alias as mainCategoryAlias ,bc.markerLocation as categoryMaker, bc.id as mainCategoryId from ( select cp2.id, cp2.name, cp2.alias, cp2.short_description, cp2.street_number, cp2.address, cp2.city, cp2.county, cp2.website, cp2.phone, cp2.email, cp2.state, cp2.fax, cp2.averageRating, cp2.slogan,cp2.logoLocation, cp2.activity_radius, cp2. review_score, cp2.featured,cp2.publish_only_city,cp2.userId, cp2.latitude, cp2.longitude, cp2.keywords,cp2.approved, cp2.mainSubcategory, cp2.countryId,cp2.typeId, cp2.postalCode, GROUP_CONCAT( DISTINCT cg.id) as categoryIds, GROUP_CONCAT(cg.name separator '#') as categoryNames, GROUP_CONCAT(cg.alias separator '#') as categoryAliases from #__jbusinessdirectory_companies cp2 left join #__jbusinessdirectory_company_category cc on cp2.id=cc.companyId left join #__jbusinessdirectory_categories cg on cg.id=cc.categoryId and cg.published=1 where 1 and cc.categoryId in (249,249) group by cp2.id ) as cp left join #__jbusinessdirectory_company_category cc on cp.id=cc.companyId left join #__jbusinessdirectory_categories cg on cg.id=cc.categoryId and cg.published=1 left join #__jbusinessdirectory_categories bc on bc.id=cp.mainSubcategory and bc.published=1 #left join #__jbusinessdirectory_company_contact cnt on cp.id=cnt.companyId left join #__jbusinessdirectory_company_types ct on cp.typeId=ct.id left join #__jbusinessdirectory_orders inv on inv.company_id=cp.id left join #__jbusinessdirectory_packages p on (inv.package_id=p.id and p.status=1 and 1) or (p.price=0 and p.status=1 and 1) left join #__jbusinessdirectory_package_fields pf on p.id=pf.package_id left join #__jbusinessdirectory_company_attributes AS ca on ca.company_id=cp.id where 1 and cc.categoryId in (249,249) and (((inv.state= 1 and now() > (inv.start_date) and (now() < (inv.start_date + INTERVAL p.days DAY) or (inv.package_id=p.id and p.days = 0)))) or p.price=0) and cp.state=1 and (cp.approved = 2 or cp.approved= -1) group by cp.id order by cp.name ) as slec left join #__jbusinessdirectory_company_ratings cra on cra.companyId=companyId1 group by companyId1 order by featured desc, packageOrder desc LIMIT 0, 20
Go Back Home