MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Ray Date:June 19 2003 3:34pm
Subject:Re: wierd sort query, how do you do it? (sort by ip proximity guess)
View as plain text  
great! that was the trick i was looking for.  thank you.
i had the feeling i was doing it the hard way :-)

On Thursday 19 June 2003 09:51, you wrote:
> Hi,
>
> If you convert the IP address into integers, then do an xor (exclusive or),
> you could call the resultant value the approximate 'distance' between the
> values.
>
> (think of the IP address in binary, any identical bits will result in 0,
> any differing will be 1.  This means that the most significant '1' will be
> the first dissimilar bit between the two IP addresses.  This is really what
> you are after.  However, including any lesser significant bits may well be
> OK for your application.)
>
> OK, so how in SQL
>
> You need to create, on the fly
>
>       ipAddress1 ^ ipAddress2
>
> (order does not matter) where they are both integers (mysql will use 64bit
> integer arithmetic).
>
> You just need to ORDER BY this value.
>
>
>
>
>
> Regards
>
>
> Matthew
>
>
> -----Original Message-----
> From: Ray [mailto:ray.list@stripped]
> Sent: 19 June 2003 15:33
> To: mysql@stripped
> Subject: wierd sort query, how do you do it? (sort by ip proximity
> guess)
>
>
> currently i have a table with an ip coloumn in text 123.45.67.89
> though it shouldn't be a big deal to convert it to binary, but was
> wondering if there is an easy way to sort by closeness to a given ip
> address?
>
> ie records that come out sorted as
> same class sub-c
> same class c
> same class c
> same class b
> same class a
> other addresses
> other addresses
>
> the only thing i can think of at this point is a really long
> order by <if same c>,<if same b>,<if same a>
Thread
wierd sort query, how do you do it? (sort by ip proximity guess)Ray19 Jun
  • RE: wierd sort query, how do you do it? (sort by ip proximity guess)Matthew Smith19 Jun
    • Re: wierd sort query, how do you do it? (sort by ip proximity guess)Ray19 Jun
    • Re: wierd sort query, how do you do it? (sort by ip proximity guess)Ray19 Jun
    • Re: wierd sort query, how do you do it? (sort by ip proximity guess)Nicholas Elliott19 Jun
      • Re: wierd sort query, how do you do it? (sort by ip proximity guess)Ray20 Jun
        • Re: wierd sort query, how do you do it? (sort by ip proximity guess)Fred van Engen20 Jun