只显示 ID 最高的行? (SQL)
我希望在我的网站上有一行,其中写着: 最新注册的人:x
人 x 是具有最高 ID 的人(即 auto_increment)..
该代码会是什么样子?
SELECT *
FROM characters
LIMIT 1
ORDER BY id
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您非常接近:
语法要求
ORDER BY
位于LIMIT
之前,并且您应该在ORDER 中添加
,获取最后一个而不是第一个用户。DESC
BYYou were very close:
The syntax requires the
ORDER BY
to come beforeLIMIT
, and you should have added aDESC
to theORDER BY
, to get the last, not the furst user.SELECT * FROM characters ORDER BY id DESC LIMIT 1
应该这样做,首先获得最高的id
。SELECT * FROM characters ORDER BY id DESC LIMIT 1
should do it, to get the highestid
first.