SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27
  1. #26
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  2. #27
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    698
    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
  •