mysql select top n max values

前端 未结 4 631
北海茫月
北海茫月 2020-11-27 07:37

How can you select the top n max values from a table?

For a table like this:

column1  column2
   1       foo
   2       foo
   3       foo
   4               


        
4条回答
  •  不知归路
    2020-11-27 07:59

    If you are using mySQl, why don't you use the LIMIT functionality? Sort the records in descending order and limit the top n i.e. :

    SELECT yourColumnName FROM yourTableName 
    ORDER BY Id desc 
    LIMIT 0,3 
    

提交回复
热议问题