Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了一个类似于下面的表,我的目标是将结果限制为 10,然后返回最后一个结果的 id,即 10。我试过做下面的查询,但它一直返回我的值 15,而不是 10。
SELECT id FROM this_table WHERE value=value ORDER BY id DESC LIMIT 10. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
select max(id) from ( SELECT id FROM this_table WHERE value = 'some_value' ORDER BY id LIMIT 10 ) x
LIMIT可以带两个参数。
LIMIT
尝试
SELECT id FROM this_table WHERE value=value ORDER BY id LIMIT 9,1
阅读所有相关信息。
编辑:哦,松开DESC零件。看来你真的不需要它。
DESC
标签