WITH combined AS ( select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 65 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where match (producttitle) against ('business services') > 6 and eliteConfirmed = 1 and ( AfricaElite='1') and b.Productid='59' limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 50 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where eliteConfirmed = 1 and ( AfricaElite='1') and b.Productid='59' limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 15 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where a.Countryid ='22' and b.Productid='59' and isElite = 0 AND EliteValidTillDate < '2025-06-26' limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat ,14 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where isElite=0 and a.Countryid ='22' and b.Productid='59' limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 12 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where match (producttitle) against ('business services') > 6 and isElite = 0 and a.Countryid ='22' limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 7 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where a.Countryid ='22' and match(activities) AGAINST ('"business services"') > 7 limit 0, 1000 UNION ALL select a.CompanyID,CompanyName,Add1,Add2,Add3,CityNameCo,a.CountryID,Pincode,TelStdCode,TelNo,FaxStdCode,FaxNo,email,website,Activities,isElite, eliteuserfilepath,EliteEnteredDate,EliteValidTillDate,producttitle,ProductDesc,productimagefilepath,eliteConfirmed ,CompanyProdID, CountryNameCo,InternetTypeCode,'' as brandimage,'' as brandname,countryshortcodeco,dontshowincountries,Google_store_applink,Apple_store_applink,price,pricecurrency, productrating,whatsappnoforchat , 6 as score from mstcompany_forsearch a inner join trncompanyprod_forsearch b on a.companyid=b.companyid where match(activities) AGAINST ('business services') > 15 limit 0, 1000 ) SELECT CompanyID, CompanyName, Add1, Add2, Add3, city, CountryID, Pincode, TelStdCode, TelNo, FaxStdCode, FaxNo, email, website, Activities, isElite, eliteuserfilepath, EliteEnteredDate, EliteValidTillDate, c.producttitle, c.ProductDesc, c.productimagefilepath, eliteConfirmed, companyproductid, CountryName, c.InternetTypeCode,brandimage,brandname,countryshortcode, score, '' as CategoryList , dontshowincountries, Google_store_applink, Apple_store_applink,price,pricecurrency,productrating,whatsappnoforchat from combined order by score desc ,EliteConfirmed desc , InternetTypeCode asc , c.productimagefilepath desc limit 0,2000 GROUP BY CompanyID LIMIT 2000