简体   繁体   English

如何在MySQL中按用户选择最后一条记录?

[英]How to select the last record by user in MySQL?

I will like to ask how I could select the last record by user in MySQL? 我想问一下如何在MySQL中按用户选择最后一条记录?

The following is my query string - which obviously did not work: 以下是我的查询字符串-显然不起作用:

SELECT *
FROM (SELECT * FROM team_notes where `username`='$username')
ORDER BY ID DESC LIMIT 1

Not sure why you use sub query for this, if you must use it, try this: 不确定为什么要使用子查询,如果必须使用,请尝试以下操作:

SELECT *
FROM (SELECT * FROM team_notes where `username`='$username') t
ORDER BY ID DESC LIMIT 1

Every sub query must have a table alias. 每个子查询都必须具有表别名。

And I think you also can do it like this: 而且我认为您也可以这样做:

SELECT * FROM team_notes WHERE `username`='$username' ORDER BY ID DESC LIMIT 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM