开发者

Only show row with highest ID? (SQL)

开发者_运维技巧I would like a one line row on my site where that reads: Latest registered person: x

And the person x is the person with highest ID (which is auto_increment)..

How would that code look like?

SELECT * 
FROM characters 
LIMIT 1 
ORDER BY id


You were very close:

SELECT *
FROM characters
ORDER BY id DESC
LIMIT 1

The syntax requires the ORDER BY to come before LIMIT, and you should have added a DESC to the ORDER BY, to get the last, not the furst user.


SELECT * FROM characters ORDER BY id DESC LIMIT 1 should do it, to get the highest id first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜