Answer the question
In order to leave comments, you need to log in
How to group records by maximum value in cell?
There is a table that looks something like this:
| title | version | identity |
|-------|---------|----------|
| Av1 | 1 | some |
| Av2 | 2 | some |
| Bv1 | 1 | any |
| Bv2 | 2 | any |
| Bv3 | 3 | any |
| Av2 | 2 | some |
| Bv3 | 3 | any |
SELECT * FROM mytable GROUP BY identity ORDER BY version DESC;
Answer the question
In order to leave comments, you need to log in
SELECT mt.* FROM mytable AS mt
INNER JOIN (
SELECT MAX(version) AS max_version FROM mytable GROUP BY identity
) AS grp
ON mt.identity = grp.identity AND mt.version = grp.max_version;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question