There is a table with many rows and fields, among the fields there are fields sub_id , date and status . Is there a way to create a sample of those lines that have the maximum date among the same sub_id , and if it suddenly happens that the maximum date not the same, then choose those who have the maximum status among those who have the same sub_id and the same maximum date ? Now I do this:
SELECT o.`id`,o.`sub_id`, o.`date`, o.`status` INNER JOIN (SELECT MAX(`date`) `max_date`, `sub_id` FROM `orders` GROUP BY `sub_id`) o2 ON o2.`max_date`=o.`date` AND o2.`sub_id`=o.`sub_id` FROM `orders` o it seems to work, but if suddenly with the same sub_id there is more than one line with the same date , then the sample selects the "first available" one, and I would like to choose the one with the most status .
Is it possible to do this?
statusat the maximumdate. - Akina