SA-MP Forums Archive
How to select only the last 10 rows from table? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to select only the last 10 rows from table? (/showthread.php?tid=328788)



How to select only the last 10 rows from table? - Bogdan1992 - 26.03.2012

The tile says everything. I searched but i didn't find a good answer.

pawn Код:
format(query, sizeof(query), "SELECT * FROM `suggestions` ORDER BY `id` DESC LIMIT 10 N-10");
N - should be the total amount of rows in the table (SELECT count(*) FROM table). You can put it in a single query using prepared queries but I'll not get into that.

Another way to do it?


Re: How to select only the last 10 rows from table? - [HiC]TheKiller - 26.03.2012

I kind of understand what you mean here. Do you want the last 10 entries rather than the highest 10 ID's? I wouldn't see much use in this as the highest ID's are probably the most recent entries.

pawn Код:
format(query, sizeof(query), "SELECT * FROM `suggestions` ORDER BY `id` DESC LIMIT 10");
What's so wrong with that?


Re: How to select only the last 10 rows from table? - Bogdan1992 - 26.03.2012

Alright its fixed now. Thank you. and yeh i tough that i need to add the total amount of rows.