SELECT `p`.`product_id`
FROM `j25_redshop_product` AS `p`
LEFT JOIN `j25_redshop_product_category_xref` AS `pc` ON `pc`.`product_id` = `p`.`product_id`
WHERE `p`.`published` = 1 AND `p`.`expired` = 0 AND `p`.`product_parent_id` = 0
GROUP BY `p`.`product_id`
ORDER BY pc.ordering ASC, pc.product_id ASC