Okay, I'm struggling here. I have a MySQL table of unsorted values that is structured about like this:
ID Size
----- -----
1 12
2 10
3 1
4 0
5 8
6 9
7 6
8 2
9 9
10 4
What I'd like to do is given a size (e.g. size = 5) extract the next bigger rows (and the next smaller eventually).
I've tried:
SELECT * FROM Table WHERE Size > 5 ORDER BY Size DESC LIMIT 2
But that gives me:
ID Size
----- -----
1 12
2 10
but what I want is
ID Size
----- -----
7 6
5 8
Any help would be appreciated. I'm using PHP to access the table if that makes a difference. Thanks!
You are using DESC that fetching result in descending . you should use ASC that will fetch results in ascending.
Example-
SELECT * FROM Table WHERE Size > 5 ORDER BY Size ASC LIMIT 2
EDITED
You need to first fetch in descending order then you need to again order by ascending.
Example-
SELECT * FROM
(SELECT * FROM Table WHERE Size > 5 ORDER BY Size DESC ) AS r
ORDER BY r.Size ASC LIMIT 2
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments