Is enrol_id unique in the table? If not, then the query could potentially return multiple rows for a given (g_id, id) combination, with the same enrol_id but different update_time and posted_time, which would contradict the effort of the ORDER BY.

Without fully understanding the business logic, one alternative to the query using JOIN could be something like:

Comment

select e.* from customer e, (select e1.g_id, e1.enrol_id from customer e1 where e1.id=324 and e1.g_id IN('x133fv','be6544','e992170','93611c') order by e1.update_time DESC, e1.posted_time DESC, e1.enrol_id DESC) t where e.id = 324 and e.g_id = t.g_id and e.enrol_id = t.enrol_id group by e.g_id, e.id;
Now my question here is question here is : Will the inner sort guarantee that i get latest record since im doing a outer group by clause. Will anytime mysql change it algo to sort differently inner query join with outer group by.