我需要 MySQL SELECT 查询方面的帮助
我需要帮助来编写一个 MySQL 查询,该查询将为我执行以下操作:
它将从某个列中选择最后一行。假设表名是“mysite_codes”,列名是“code”,这一列中有很多行,但我希望查询获取最后添加的行并在 PHP 中返回一个结果(LIMIT 1 件事) 。
有人可以帮我解决这个问题吗?
I need help to write a MySQL query that would do the following for me:
It would select the last row from a certain column. Let's say the table name is 'mysite_codes' and the column name is 'code', there are many rows in this column, but I want the query to take the last added one and get my back one result in PHP (LIMIT 1 thing).
Would anyone please help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MySQL 表没有固有的排序。如果您想要“最后添加的”,那么您需要一个
AUTO_INCRMENT
ing 列,例如id
。然后就可以写了。
只获取
id
值最高的行。MySQL tables have no inherent sorting. If you want "the last added one" then you'll need an
AUTO_INCREMENT
ing column likeid
.Then you can write.
to get just the row with the highest
id
value.试试这个:
Try this:
假设您有一个名为“auto_id_column”的自动递增 id 列:
Assuming you have an auto-incremementing id column called something like "auto_id_column":