QUERY:
SELECT
t1.*,
t1.id as product_id,
t2.brand_name,
t2.brand_website,
t3.unit_name,
DATE_FORMAT(t1.created, '%d.%m.%Y') as created2,
IF(t1.name_et != '', t1.name_et, t1.name_et) as name,
IF(t1.description_et != '', t1.description_et, t1.description_et) as description,
IF(t1.url_code_et != '', t1.url_code_et, t1.url_code_et) as url_code,
IF(price_discount > 0 AND price_discount < price, price_discount, price) as current_price,
IF(price_discount > 0 AND price_discount < price, 1, 0) as is_discounted,
(SELECT fk_category_id FROM mdl_shop_product_category WHERE fk_product_id = t1.id ORDER BY fk_category_id DESC LIMIT 1) as main_cat_id,
(SELECT COUNT(*) FROM mdl_shop_product_files WHERE type='image' AND fk_product_id = t1.id LIMIT 1) as images_count FROM mdl_shop_products AS t1
LEFT JOIN mdl_shop_brands AS t2 ON t1.fk_brand_id = t2.id
LEFT JOIN mdl_shop_units AS t3 ON t1.fk_unit_id = t3.id WHERE t1.active = 1 AND t1.deleted = 0 AND name_et != '' ORDER BY event_time DESC, id DESC LIMIT -15, 15