mysqlselectlimits

MySQL: How to select all rows from a table EXCEPT the last one


I have a table with N rows, and I wanna select N-1 rows.

Suggestions on how to do this in one query, if it's possible..?


Solution

  • 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 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.