I have a table with an id column (_id, integer) and a post_id column (_post_id, string) in a tbl_messages table.
I would like to make a query where I can know the position of the row in a simple query without LIMIT, to put it in the OFFSET.
I could make a query and in PHP with a search_array get the position, but I would like to do it in the same query.
For example:
SELECT * FROM tbl_messages WHERE _user = '2' AND _instance = '5' ORDER BY _date ASC LIMIT 10, OFFSET (Here I would like to return the position in the result, and start the result list from post_id = 'R5G96H5D85S9' by example).
I couldn’t find anything that satisfied my interest in hours of searching, I appreciate any attempt to give me an idea;
Thanks
2
Answers
Well, sorry to those who said it wasn't possible and gave up at the same time. For those who come to this question looking for answers, I got it this way:
This can be written in PHP like this:
You cannot do what you describe in one query, because the arguments to
LIMIT
andOFFSET
can’t be expressions or subqueries.So you must calculate the position before you run the query. You said you already know how to do this.
You are allowed to use an integer parameter or a variable as the argument to
LIMIT
.(notice I removed the comma before OFFSET)