- En una tabla derivada, obtenga el valor de versión máximo para cada type_id
- Únete a la tabla principal para obtener la fila correspondiente.
Prueba lo siguiente:
SELECT e.*
FROM
example1 AS e
JOIN
(
SELECT type_id,
MAX(version) AS maximum_version
FROM example1
WHERE class_id = 10
GROUP BY type_id
) AS dt ON dt.type_id = e.type_id AND
dt.maximum_version = e.version
WHERE e.class_id = 10
Resultado
| id | version | text | class_id | type_id |
| --- | ------- | ----- | -------- | ------- |
| 1 | 1 | text1 | 10 | 1 |
| 2 | 1 | text2 | 10 | 2 |
| 4 | 1 | test4 | 10 | 4 |
| 9 | 3 | last | 10 | 3 |
| 11 | 3 | rrrr | 10 | 5 |