How to select data where a field has a min value in MySQL?

后端 未结 7 1254
半阙折子戏
半阙折子戏 2020-12-02 17:02

I want to select data from a table in MySQL where a specific field has the minimum value, I\'ve tried this:

SELECT * FROM pieces WHERE MIN(price)


        
相关标签:
7条回答
  • 2020-12-02 17:54

    In fact, depends what you want to get: - Just the min value:

    SELECT MIN(price) FROM pieces
    
    • A table (multiples rows) whith the min value: Is as John Woo said above.

    • But, if can be different rows with same min value, the best is ORDER them from another column, because after or later you will need to do it (starting from John Woo answere):

      SELECT * FROM pieces WHERE price = ( SELECT MIN(price) FROM pieces) ORDER BY stock ASC

    0 讨论(0)
提交回复
热议问题