Select Highest Value In Each Group

Create Table Of Adventurers

-- Create table called adventurers
CREATE TABLE adventurers (
    -- string variable
    name varchar(255),
    -- integer variable
    age int,
    -- string variable
    race varchar(255)

Insert Rows

-- Insert into the table adventurers
INSERT INTO adventurers (name, age, race)
VALUES ('Fjoak Doom-Wife', 28, 'Human'),
       ('Alooneric Cortte', 29, 'Human'),
       ('Piperel Ramsay', 35, 'Elf'),
       ('Casimir Yardley', 14, 'Elf')

Select The Oldest Adventurer In Each Race

-- Get the name, race, age of the first row in each group, 
-- when grouped by race
SELECT DISTINCT ON (race) name, race, age FROM adventurers
-- Order by race, then age, in descending order 
-- (so the oldest person is the top of each group)
ORDER BY race, age DESC
Piperel RamsayElf35
Alooneric CortteHuman29