SELECT a.name, a.alias, a.id, a.image, a.category_alias, a.category_id,a.price,a.price_old,a.discount,
a.new_prd, a.h_price,a.h_price_old,a.summary,a.is_hotdeal,a.date_end,a.date_start,a.promotion_price,
a.link_orther,a.text_old,a.is_renew, a.is_autumn,a.is_card, a.is_installment, a.is_km3,
a.image_sticker_oldprd,a.note_oldprd,a.show_price7, b.fdate,b.tdate, sub.price_1
FROM fs_products AS a
LEFT JOIN fs_sales_categories as b ON a.sale_id = b.id
LEFT JOIN (
SELECT product_id, price_h, price_1
FROM fs_products_sub
WHERE published = 1
GROUP BY product_id, price_h
) as sub ON (a.id = sub.product_id AND a.h_price = sub.price_h)
WHERE (a.category_id_wrapper like '%,145,%' OR a.category_id_wrapper1 like '%,145,%')
AND a.published = 1 AND a.show_cat = 0
ORDER BY a.ordering ASC, a.id DESC SELECT a.name, a.alias, a.id, a.image, a.category_alias, a.category_id,a.price,a.price_old,a.discount,
a.new_prd, a.h_price,a.h_price_old,a.summary,a.is_hotdeal,a.date_end,a.date_start,a.promotion_price,
a.link_orther,a.text_old,a.is_renew, a.is_autumn,a.is_card, a.is_installment, a.is_km3,
a.image_sticker_oldprd,a.note_oldprd,a.show_price7, b.fdate,b.tdate, sub.price_1
FROM fs_products AS a
LEFT JOIN fs_sales_categories as b ON a.sale_id = b.id
LEFT JOIN (
SELECT product_id, price_h, price_1
FROM fs_products_sub
WHERE published = 1
GROUP BY product_id, price_h
) as sub ON (a.id = sub.product_id AND a.h_price = sub.price_h)
WHERE (a.category_id_wrapper like '%,143,%' OR a.category_id_wrapper1 like '%,143,%')
AND a.published = 1 AND a.show_cat = 0
ORDER BY a.ordering ASC, a.id DESC SELECT a.name, a.alias, a.id, a.image, a.category_alias, a.category_id,a.price,a.price_old,a.discount,
a.new_prd, a.h_price,a.h_price_old,a.summary,a.is_hotdeal,a.date_end,a.date_start,a.promotion_price,
a.link_orther,a.text_old,a.is_renew, a.is_autumn,a.is_card, a.is_installment, a.is_km3,
a.image_sticker_oldprd,a.note_oldprd,a.show_price7, b.fdate,b.tdate, sub.price_1
FROM fs_products AS a
LEFT JOIN fs_sales_categories as b ON a.sale_id = b.id
LEFT JOIN (
SELECT product_id, price_h, price_1
FROM fs_products_sub
WHERE published = 1
GROUP BY product_id, price_h
) as sub ON (a.id = sub.product_id AND a.h_price = sub.price_h)
WHERE (a.category_id_wrapper like '%,151,%' OR a.category_id_wrapper1 like '%,151,%')
AND a.published = 1 AND a.show_cat = 0
ORDER BY a.ordering ASC, a.id DESC