[thelist] selecting above and below ranges in a SQL query [long]

rudy r937 at interlog.com
Mon Aug 26 13:12:01 CDT 2002


>  mysql> select * from ErlangTest
>      -> where erlang_no <= '1.5'
>      -> limit 3;

you'll need to sort, in order for this to work

you'll need two queries, one for the lower ones sorted descending, and one
for the higher ones ascending

if mysql did unions, it would be one query


> Will I have to programatically loop

aaugh!!


> The desired outcome is to get the one equal to (if there is a match),
>  the 3 above, and the 3 below that value, so that the value stated in
> the query (1.5) returns (there is no row matching 1.5);

you actually want 0 results if you don't match an existing value?

or do you want 6 rows instead of the 7 you'd get with a match?


rudy
http://rudy.ca/






More information about the thelist mailing list