jaymc Posted August 6, 2008 Share Posted August 6, 2008 Lets say I have a table, in that table there is a field where a number can be between 0-100,000 I want to pull out all records closest to a number I specify For instance if the number I specify is 800, it should return 799, 801, 798, 802, 797, 803 NOT 801, 802, 803 or vice versa which is what I would get using a standard order. I cant use BETWEEN or < > because the closest number to a number I specify maybe 350 digits away, its dynamic Just think of it as a program which calculates the 10 closest people to someone standing directly in the middle of a circle. Each time you load the script the position of the people are different, hence cant use BETWEEN etc Im actually using this to calculate the people closest to a postcode based on long and lat, but the circle example will surfice! Any ideas on the best way to do this in pure MYSQL Quote Link to comment Share on other sites More sharing options...
fenway Posted August 6, 2008 Share Posted August 6, 2008 Unless you know the distribution in advance, you can't do this very easily -- you can kludge it, but it's not great. And lat/long is a completely different issue. Quote Link to comment Share on other sites More sharing options...
jaymc Posted August 6, 2008 Author Share Posted August 6, 2008 Kludge it? Ok lets say I did know the distribution, so I use BETWEEN How can I get it to order it by INTRO/OUTRO as in closest to the number specified Quote Link to comment Share on other sites More sharing options...
fenway Posted August 6, 2008 Share Posted August 6, 2008 Well, if you know how many are in between, then you can multiply by the gap (plus an extra 50% fudge factor), and then "mark" the middle row, and work backwards. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.