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 ptc.categories_id = 6 and p.manufacturers_id = 134
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
Sort by
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 p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = '6' or p2c.categories_id = '7' or p2c.categories_id = '33' or p2c.categories_id = '39' or p2c.categories_id = '115' or p2c.categories_id = '123' or p2c.categories_id = '135' or p2c.categories_id = '151') and m.manufacturers_id = '134' 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