How can I select the row with the highest ID in MySQL?

后端 未结 9 2055
故里飘歌
故里飘歌 2020-12-24 11:06

How can I select the row with the highest ID in MySQL? This is my current code:

SELECT * FROM permlog WHERE max(id)

Errors come up, can som

9条回答
  •  温柔的废话
    2020-12-24 11:27

    For MySQL:

    SELECT *
    FROM permlog
    ORDER BY id DESC
    LIMIT 1
    

    You want to sort the rows from highest to lowest id, hence the ORDER BY id DESC. Then you just want the first one so LIMIT 1:

    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement.
    [...]
    With one argument, the value specifies the number of rows to return from the beginning of the result set

提交回复
热议问题