SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: Select Nearest Value

  1. #26
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    MIN(ABS()) gives the smallest difference on either side (that's what the ABS function does -- it smooshes negatives into positives)

    so no, i don't think you need both of those subqueries
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  2. #27
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    672
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's what I thought, yet when I use your original query I always get the nearest value that is greater than 50, so with 50, 51 and 52 I am getting 53 returned, instead of 49. My query is returning the nearest below 50 and the nearest above 50. I'm just picking the one with the lowest difference in PHP to get the result. It works, but it's far from elegant

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •