SELECT p.*, p.code1 as innercode, (SELECT productId FROM qc_products WHERE code1=innercode and mainImageId<>0 order by isMain desc LIMIT 1) as mainproductId , (SELECT mainImageId FROM qc_products WHERE code1=innercode and mainImageId<>0 order by isMain desc LIMIT 1) as mainmainImageId ,p.name as pname FROM qc_products as p, qc_productInCategories as pc WHERE p.isMain=1 AND p.productId = pc.productId AND p.datevisible<='2018-05-22 03:08:48' UNION SELECT p.*, p.code1 as innercode, (SELECT productId FROM qc_products WHERE code1=innercode and mainImageId<>0 order by isMain desc LIMIT 1) as mainproductId , (SELECT mainImageId FROM qc_products WHERE code1=innercode and mainImageId<>0 order by isMain desc LIMIT 1) as mainmainImageId,p.name as pname FROM qc_products as p, qc_productInCategories as pc WHERE p.isMain=0 AND p.productId = pc.productId AND pc.categoryId IN ( 46,17,119 ) AND p.datevisible<='2018-05-22 03:08:48' GROUP BY p.productId ORDER BY pname asc limit 0,32
More Results:
More Results: