且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL:如何从表中选择除最后一行以外的所有行

更新时间:2023-01-24 18:49:52

最后一行的ID是否最高?如果是这样,我认为这会起作用:

Does the last row have the highest ID? If so, I think this would work:

SELECT * FROM TABLE WHERE ID != (SELECT MAX(ID) FROM TABLE)

MySQL确实允许在当前版本中进行子选择,对吧?

MySQL does allow subselects in the current version, right?

但是,在大多数情况下,如果选择了所有行,然后在应用程序中过滤掉了不需要的数据,它的性能可能会更好.

However, in most cases, it'd probably perform better if you selected all the rows and then filtered the unwanted data out in your application.