You don't mention the database you are using. Most databases support the ANSI standard row_number()
and window/analytic functions. Here is one method to do what you want:
select type, name, price
from (select t.*, row_number() over (partition by type order by price desc) as seqnum
from titles t
) t
where seqnum = 1;
In the case of MySQL, which does not support row_number()
, you can do:
select type,
substring_index(group_concat(name separator '|' order by price desc), '|', 1) as title,
max(price) as price
from titles
group by type;
Note that this assumes that no title contains the character '|'
.