List:General Discussion« Previous MessageNext Message »
From:Carsten H. Pedersen Date:November 18 2000 12:25pm
Subject:RE: Between and negative numbers
View as plain text  
> I can code to select latitudes BETWEEN certain values. But it won't work
> with the LONGITUDES.
> eg: I'd like to say
> select count(*) from test_table where latitude between 40.589506 and
> 40.589992
> and longitude between -73.922080 and -73.922420.
> 
> I should only get 10 out of the above rows. I get none.
> Both Latitude and Longitude are defined as decimal 9 6
> Could anyone offer any guidance?
> TIA
> Kieran Ames
> 

Reading The Fine Manual:
--
expr BETWEEN min AND max 
  If expr is greater than or equal to min and expr 
  is less than or equal to max, BETWEEN returns 1, 
  otherwise it returns 0. This is equivalent to the 
  expression (min <= expr AND expr <= max) if all the 
  arguments are of the same type.
--
I.e. you must put the smallest of the two numbers
(the numerically larger of the negative values)
before 'and' like so :

  select count(*) from test_table 
  where latitude between 40.589506 and 40.589992 and 
        longitude between -73.922420 and -73.922080.

/ Carsten
--
Carsten H. Pedersen
keeper and maintainer of the bitbybit.dk MySQL FAQ
http://www.bitbybit.dk/mysqlfaq

Thread
Between and negative numbersKieran Ames18 Nov
  • RE: Between and negative numbersCarsten H. Pedersen18 Nov
    • Re: Between and negative numbersKieran Ames18 Nov
      • Re: Between and negative numbersBob Hall20 Nov