This is your query:
SELECt *FROM (SELECt * FROM user_comission_configuration_history ORDER BY on_date DESC ) AS ordered_historyWHERe user_id = 408002GROUP BY comission_id;
One major problem with your query is that it uses a MySQL extension to
groupbythat MySQL explicitly warns against. The extension is the use of other
columns in the in the
selectthat are not in the
group byor in aggregation
functions. The warning (here) is:
MySQL extends the use of GROUP BY so that the select list can refer to
nonaggregated columns not named in the GROUP BY clause. This means that the
preceding query is legal in MySQL. You can use this feature to get better
performance by avoiding unnecessary column sorting and grouping. However,
this is useful primarily when all values in each nonaggregated column not
named in the GROUP BY are the same for each group. The server is free to
choose any value from each group, so unless they are the same, the values
chosen are indeterminate.
So, the values returned in the columns are indeterminate.
Here is a pretty efficient way to get what you want (with “comission” spelled
correctly in English):
SELECt *FROM user_commission_configuration_history cchWHERe NOT EXISTS (select 1 from user_commission_configuration_history cch2 where cch2.user_id = cch.user_id and cch2.commission_id = cch.commission_id and cch2.on_date > cch.on_date ) AND cch.user_id = 408002;



