SELECT * FROM corsi INNER JOIN edizioni ON product_id=corso_id INNER JOIN corsi_cat ON cat_id=category_id LEFT JOIN corsi_subcat ON id_subcat=subcat_id WHERE cat_id='9' AND new_publish='Y' AND product_publish='Y' GROUP BY product_id ORDER BY product_publish DESC, product_sku ASC