Sqlite 获取最大 ID 不起作用(?) [英] Sqlite get max id not working (?)
本文介绍了Sqlite 获取最大 ID 不起作用(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个:
SELECT *
WHERE id=MAX(id)
FROM history;
但我的查询是空的.我也试过这个(这个有效):
But my query is empty. I have also tried this (This one works):
SELECT MAX(id) AS max_id
FROM history;
但显然我的查询只包含 max_id 键.第一个我做错了什么?
But obviusly my query only contains the max_id key. What am I doing wrong with the first one?
推荐答案
您需要为 MAX
添加另一个级别的 select
,如下所示:
You need to add another level of select
for the MAX
, like this:
SELECT *
WHERE id=(SELECT MAX(id) from history)
FROM history;
更好的方法是按 id
降序排序,并将输出限制为单行:
A better approach would be to order by id
in descending order, and limit the output to a single row:
SELECT *
FROM history
ORDER BY id DESC
LIMIT 1
这篇关于Sqlite 获取最大 ID 不起作用(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文