How to select only the last 10 rows from table?
#1

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?
Reply
#2

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?
Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)