select distinct
ptc.categories_id, p.manufacturers_id, pm.ID as model_ID , p.products_price, pef.products_extra_fields_id, pef.products_extra_fields_name, ptpef.products_extra_fields_value, pef.products_extra_fields_order, pef.products_extra_fields_facet, ptpef.products_id
from products_to_categories ptc
inner join products p on p.products_id = ptc.products_id
left join products_to_products_extra_fields ptpef on ptpef.products_id = ptc.products_id
left join products_extra_fields pef on pef.products_extra_fields_id = ptpef.products_extra_fields_id
left join products_models_to_products p2m on p2m.products_id = p.products_id
left join products_models pm on pm.ID = p2m.model_id
where
(p.products_status = 1)
and (pef.products_extra_fields_status = 1 or pef.products_extra_fields_status is null)
and (pef.languages_id = 1 or pef.languages_id = 0 or pef.languages_id is null)
and p.manufacturers_id = 81 and p.products_id in (7959,7960,7969,7973,7974,7975,20843,20844,20846,20848,20849,20851,20852,20854,20855,20856,20857,20859,20861,20862,20864,20865,20876,20878,20880,20884,20892,20894,20898,20900,20906,20910,20912,20914,20918,20922,20924,20928,20932,20936,20942,20944,20948,20950,20952,20954,20956,20958,20960,20962,20964,20966,20973,20975,20978,20980,20982,20984,20986,24768,29358,67889,67891,67893,67894,67896,67898,67900,67902,67903,67904,67906,67908,67909,67911,67913,67915,67916,67918,67920,67922,67924,67926,67928,67930,67932,67934,67936,67938,67940,67942,67943,67944,67946,67948,67950,67951,67953,67955,67957,67959,67960,67961,67963,67965,67967,67969,67971,67973,67975,67977,67979,67981,67984,67985,67986,67988,67990,67992,67994,67995,68011,68013,68015,68017,68021,68023,68025,68036,68038,68039,68041,68043,68045,68046,68048,68049,68051,68053,68055,68058,68060,68062,68063,68066,68467,68469,68470,68472,68474,68476,68478,68480,68482,68488,68489,68491)
and (p.products_group_access like "%,G,%" or p.products_group_access like "G,%" or p.products_group_access like "%,G" or p.products_group_access="G")
order by
products_extra_fields_order, products_extra_fields_name, (products_extra_fields_value+0), products_extra_fields_value, p.products_id
select p.products_image, p.products_model, p.products_quantity, p.products_date_available, p.products_date_order_due, pm.ID, m.manufacturers_id, p.products_parent_id, p.products_id, pd.products_name, p.products_price, p.products_price1, p.products_price2, p.products_price3, p.products_price4, p.products_price5, p.products_price6, p.products_price7, p.products_price8, p.products_price9, p.products_price10, p.products_price11, p.products_price1_qty, p.products_price2_qty, p.products_price3_qty, p.products_price4_qty, p.products_price5_qty, p.products_price6_qty, p.products_price7_qty, p.products_price8_qty, p.products_price9_qty, p.products_price10_qty, p.products_price11_qty, p.products_qty_blocks, p.vendors_prod_id, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from ( products p
left join specials s on (s.products_id = p.products_id and s.status = 1))
left join manufacturers m on p.manufacturers_id = m.manufacturers_id left join products_models_to_products p2m on p.products_id=p2m.products_id left join products_models pm on pm.ID = p2m.model_id left join products_to_products_extra_fields p2pef on p.products_id = p2pef.products_id , products_description pd, categories c, products_to_categories p2c where (p.products_status = 1) and p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and m.manufacturers_id = '81' and (p.products_group_access like "%,G,%" or p.products_group_access like "G,%" or p.products_group_access like "%,G" or p.products_group_access="G") group by p.products_id order by p.products_sort_order, p.products_date_available desc, p.products_last_views desc, pd.products_name