First of all, I've tried to google this, but only came up with this kind of answer: MySQL - Get row number on select
What I need is, to "get row position by speciefic id".
With the example from above link, I tried to add the "WHERE CLAUSE", but, the result of "rank" was always 1.
So, if my table has auto increment id field, and is not in specific order (for example, after id 1 comes 3, not 2, because id 2 was deleted from database), how can I get the position of for example id 4?
Is there any possible way to get, what I want?
Assuming that, by "position", you mean when ordered by id
:
SELECT COUNT(*) FROM my_table WHERE id <= 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With