mysql: select max(score) doesn't return the relevant row data

后端 未结 3 607
温柔的废话
温柔的废话 2020-12-10 22:31

if i have for example a scores table:

    user game score timestamp
    1    50   50    date
    2    60   40    date
    3    70   25    date
    4    80   18            


        
3条回答
  •  眼角桃花
    2020-12-10 23:06

    As you're not using a GROUP clause, the max function is returning the maximum value from across the table. As such, if you want to return the matching data for the highest score, you'd need to:

    SELECT * FROM table_name ORDER BY score DESC LIMIT 1
    

提交回复
热议问题