MySQL SELECT unique column where other column is max

前端 未结 3 1245
无人共我
无人共我 2021-01-20 17:31

I have table like this

  id     |     serial_num     |      version     | .....
  1      |         1          |          1       | .....
  2      |         2         


        
3条回答
  •  滥情空心
    2021-01-20 18:04

    Selecting id for a group by query is useless. You should only select the column you are using in group by and other columns that are being applied aggregate functions.

    Hope this works for you.

    SELECT id, 
           serial_num, 
           Max(`version`) `version`
    FROM   tbl1 
    GROUP  BY serial_num 
    

提交回复
热议问题