Sorry for the strange title, but I don't know how else to describe what I'm trying to achieve.
Imagine a table tblTable (all three columns are integers) :
[tt]
ID Int1 Int2
1 10101 100
1 10102 25
1 10102 50
2 10013 65
[/tt]
I want a simpler way of finding the maximum aggregates. I can do this like this :
SELECT ID, MAX(Int2), Xnt1
FROM tblTable
INNER JOIN (SELECT ID AS XID, MAX(Int1) AS Xnt1 FROM tblTable GROUP BY ID)
X ON XID=ID AND Xnt1=Int1
GROUP BY ID
Returning :
[tt]
1 10102 50
2 10013 65
[/tt]
I hope someone understands what I mean, not the same as :
SELECT ID, MAX(Int2), MAX(Int1) FROM tblTable GROUP BY ID
I want the maximum value of Int2 when Int1 is at its maximum. Perhaps there's an easier way than having a sub-query using the same table twice?
Thanks!
Bob
Imagine a table tblTable (all three columns are integers) :
[tt]
ID Int1 Int2
1 10101 100
1 10102 25
1 10102 50
2 10013 65
[/tt]
I want a simpler way of finding the maximum aggregates. I can do this like this :
SELECT ID, MAX(Int2), Xnt1
FROM tblTable
INNER JOIN (SELECT ID AS XID, MAX(Int1) AS Xnt1 FROM tblTable GROUP BY ID)
X ON XID=ID AND Xnt1=Int1
GROUP BY ID
Returning :
[tt]
1 10102 50
2 10013 65
[/tt]
I hope someone understands what I mean, not the same as :
SELECT ID, MAX(Int2), MAX(Int1) FROM tblTable GROUP BY ID
I want the maximum value of Int2 when Int1 is at its maximum. Perhaps there's an easier way than having a sub-query using the same table twice?
Thanks!
Bob