如何选择表中具有最大 ID 的整行? [英] How do I select an entire row which has the largest ID in the table?

查看:29
本文介绍了如何选择表中具有最大 ID 的整行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么做这样的事情?

<前>SQL SELECT row FROM table WHERE id=max(id)

解决方案

您可以使用子选择:

SELECT 行发件人表哪里 id=(SELECT max(id) FROM 表)

请注意,如果max(id) 的值不唯一,则返回多行.

如果您只想要一个这样的行,请使用@MichaelMior 的答案,

SELECT row from table ORDER BY id DESC LIMIT 1

How would I do something like this?

SQL SELECT row FROM table WHERE id=max(id)

解决方案

You could use a subselect:

SELECT row 
FROM table 
WHERE id=(
    SELECT max(id) FROM table
    )

Note that if the value of max(id) is not unique, multiple rows are returned.

If you only want one such row, use @MichaelMior's answer,

SELECT row from table ORDER BY id DESC LIMIT 1

这篇关于如何选择表中具有最大 ID 的整行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆