SELECT `products`.`id`, `products`.`name`, `products`.`sku`, `products`.`tags`, `products`.`seo_url`, `products`.`master_img`, `category_product_position`.`id` AS `position_id`, `position`, `price`, `compare_at_price`, `products`.`sale_count`, `option1_values` FROM `products` LEFT JOIN `category_products` ON category_products.product_id=products.id LEFT JOIN `category_product_position` ON category_product_position.product=products.id and category_product_position.category=584 WHERE (category_products.category_id=584) AND (products.status=1) GROUP BY `products`.`id` ORDER BY `category_product_position`.`position` DESC, `id` DESC LIMIT 5