MySQL Forums
Forum List  »  Newbie

Help with minimum/group by
Posted by: Brendan Moran
Date: November 08, 2009 12:04AM

Suppose I have a simple table:

closest:
+---+-------+
| a | b |
+---+-------+
| 1 | 1 |
| 2 | 5.7 |
| 3 | 15.9 |
| 4 | 6.8 |
| 5 | 17 |
| 6 | -12.7 |
+---+-------+

And I want to find the closest match to b=14.3. My query would be:
SELECT MIN(ABS(14.3-b)),a,b FROM closest;
However, this is a syntax error, as I'm mixing group and non-group columns with no group-by statement. How do I return not only the minimum, but also the row that it matched on?

Thanks,
Annirak

Options: ReplyQuote


Subject
Written By
Posted
Help with minimum/group by
November 08, 2009 12:04AM
November 08, 2009 11:37AM
November 08, 2009 03:37PM
November 08, 2009 05:55PM
November 08, 2009 06:10PM
November 08, 2009 06:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.