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
| SitePoint Sponsor |


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




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