i ve a little problem in sql, i can’t reach a way to build the correct statement. i need to include in the result only the row having the maximum “sess” when “etud” and “mod” are equal in the occurrences :
etud|sess|mod|eta
1------1---M1--nv
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v
now the result i need is :
etud|sess|mod|eta
1------2---M1--v
2------1---M1--nv
3------1---M1--v
4------1---M1--v
Thanks in advance .
This is really just a
MAX()aggregate, grouping byetudandmod:Update after edited quetsion:
Although MySQL will allow you to simply add the column to the query above without adding it to the
GROUP BY, the value you get for that column is non-deterministic and if you have multiple possible values, you can’t plan on which one you’ll get back (usually it will be the first one though).To pull in the remaining
etacolumn matching theMAX(sess)you can join against a subquery.