[thelist] selecting above and below ranges in a SQL query [long]
Chris Johnston
chris at fuzzylizard.com
Mon Aug 26 13:16:01 CDT 2002
Jay Blanchard wrote:
>mysql> select * from ErlangTest
> -> where erlang_no <= '1.5'
> -> limit 3;
>+----+-----------+
>| id | erlang_no |
>+----+-----------+
>| 1 | 0.00001 |
>| 2 | 0.00567 |
>| 3 | 0.00883 |
>+----+-----------+
>
>
This query is doing exactly what you are asking it to. It takes the
first three results that it finds that are less then or equeal to 1.5,
You need to figure out a way to take the last three.
>But I want to get;
>+----+-----------+
>| id | erlang_no |
>+----+-----------+
>| 5 | 1.00238 |
>| 6 | 1.06565 |
>| 7 | 1.08970 |
>+----+-----------+
>
>
I don't know if this will work but maybe try something like this
mysql> select * from ErlangTest
-> where erlang_no <= '1.5'
-> order erlang_no DESC
-> limit 3;
In order to get the three after, just use this
mysql> select * from ErlangTest
-> where erlang_no >= '1.5'
-> limit 3;
This will find the first three entries greater then 1.5 and display them
for you.
Don't know if that helps.
//chris
More information about the thelist
mailing list