I have a table (rather ugly designed, but anyway), which consists only of strings. The worst is that there is a script which adds records time at time. Records will never be deleted.
I believe, that MySQL store records in a random access file, and I can get last or any other record using C language or something, since I know the max length of the record and I can find EOF.
When I do something like "SELECT * FROM table
" in MySQL I get all the records in the right order - cause MySQL reads this file from the beginning to the end. I need only the last one(s).
Is there a way to get the LAST record (or records) using MySQL query only, without ORDER BY
?
Well, I suppose I've found a solution here, so my current query is
SELECT
@i:=@i+1 AS iterator,
t.*
FROM
table t,
(SELECT @i:=0) i
ORDER BY
iterator DESC
LIMIT 5
If there's a better solution, please let me know!