9951 explained code solutions for 126 technologies


mysqlSelect last record from group


SELECT id, name FROM table WHERE id IN ( SELECT max(id) FROM table GROUP BY name )ctrl + c
SELECT id, name

columns to select

table

table name to select from (definition)

WHERE id IN

select only certain ids, defined by subquery

SELECT max(id) FROM table GROUP BY name

subqyery will return last (maximum) ids for each unique name value