![](/img/trans.png)
[英]MySQL: How do I get a piece of information from one table based on it's id in another table
[英]How do I get the max id from the first n id's in a MySQL table?
我正在尝试获取MySQL数据库表中前n个id的最大id
,其中id不一定是顺序的。 前n个ID由id
升序确定。 我正在使用以下查询,但这将返回整个表中的最大ID。
SELECT MAX( id )
FROM files
ORDER BY id ASC
LIMIT 8750000
我在做什么错,或者...我该怎么做?
SELECT MAX(t.id) FROM
(SELECT id FROM files order by id ASC limit <n>) AS t ;
当然,您需要将<n>
替换为所需的实际值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.