I couldn’t find a way to do it and am not sure how to search for this question, as all I’ve found were not exactly what I wanted and the answers not applicable.
I have a table with two fields (char and num), ‘num’ is unique but ‘char’ not, as in the example:
char | num
_________
a | 2
b | 1
c | 3
c | 4 <-- I am here
c | 7
c | 8
d | 5
e | 9
f | 6
what I want is to fetch N rows beginning in the line marked with the table ordered by ‘char’.
I’m using
SELECT * FROM table WHERE char >= $current_char ORDER BY char,num LIMIT $N
but it doesn’t do what I want, as it starts from the row with char=’c’ and num=’3′.
EDIT: I will probably count and use xdazz’s answer because the code will be clearer, but it looks that I could do this other way:
SELECT * FROM table WHERE char > $current_char OR (char = $current_char AND num >= $current_num) ORDER BY char,num LIMIT $N
but it is not very pretty.
You marked
<-- I am heremeans you know that is the forth record, so you could just do :