lyonTypescript
lyonTypescript

Reputation: 135

Mysql - group showing all the data the last row by group

The question is the following: How can I group in the table, but showing all the data the last row the group

Query Table

score  team    stadium            date
20     Ajax    Arena Stadium      '26/Feb/2020'
10     Madrid  Santiago Bernabeu  '26/Feb/2020'
10     Ajax    Arena Stadium      '22/Feb/2020'

Expected result

score  team    stadium            date
20     Ajax    Arena Stadium      '26/Feb/2020'
10     Madrid  Santiago Bernabeu  '26/Feb/2020'

Regards

Upvotes: 0

Views: 40

Answers (1)

Eric
Eric

Reputation: 3257

Try this

SELECT score, team, stadium, date
FROM (
    SELECT 
        , ROW_NUMBER() OVER(PARTITION BY score, team ORDER BY date DESC) AS rn
    FROM yourTable
) tbl
WHERE rn = 1

Upvotes: 1

Related Questions