SELECT t.id
, t.ref
, t.name
, t.type
, t.value
FROM ( SELECT type
, MAX(id) AS latest
FROM daTable
GROUP
BY type ) AS m
INNER
JOIN daTable AS t
ON t.type = m.type
AND t.id = m.latest
run the subquery by itself, inspect the results, and imagine the results are a separate table – now imagine this separate table joined back to your original table using those two join columns to identify which complete table rows to return