Hey!
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..?
Hey!
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..?
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.
SELECT DISTINCT t1.columns FROM table t1
INNER JOIN table t2 ON t1.id < t2.id
In my experience, MySQL loves this technique, going back several versions.