Grouping by Column with Dependence on another Column

后端 未结 2 1051
无人共我
无人共我 2021-01-19 04:04

Here is a simplified look at the problem I am trying to cleanly solve via a MySQL query. This is not the actual table I am dealing with.

If I have the following ta

2条回答
  •  梦谈多话
    2021-01-19 04:28

    Another alternative is to load the data sorted in a subquery, then group on the results. I can't cite this, but I've read in a few places there's no (discernable) performance hit on this.

    So something like:

    SELECT * 
    FROM (
        SELECT * 
        FROM `yourtable` 
        ORDER BY `id` DESC
    ) as `tmp` 
    GROUP BY `name`
    

提交回复
热议问题