I'm not sure if you can do it in one query, but you can definitely do it
in two:
SELECT max(A) FROM T WHERE B = 5;
SELECT * FROM T WHERE A = ? AND B = 5; -- bind ? to max(a) above
Tim McDaniel wrote:
All,
This should be easy, but this non SQL guru can't figure it out...
Given a table T like this:
A B
---------
1 5
2 5
3 5
I need a query to give me just the row with the largest A value, within
a group defined by B. In this case, it would be the row with A = 3.
Something like:
SELECT * FROM T
GROUP BY B
ORDER BY A;
It doesn't seem to matter if I use ASC or DESC for the ordering, it
always gives me the row with A = 1.
Any ideas?
Thanks,
Tim McDaniel