April 6, 2006 at 3:28 am
i have one table
id class date
1 1 2/mar/2005
1 2 2/mar/2006
2 4 2/mar/2006
2 3 2/mar/2003
3 2 2/mar/2005
4 1 2/mar/2002
4 2 2/mar/2003
now i want only records with latest date
1 2 2/mar/2006
2 4 2/mar/2006
3 2 2/mar/2005
4 2 2/mar/2003
without using subquery
April 6, 2006 at 3:58 am
Is the latest date always going to have the highest class?
If so:
SELECT id, MAX(class), MAX(date)
FROM table
GROUP BY id
If that rule doesn't hold though, you'll get spurious results.
April 6, 2006 at 4:04 am
You need the max date... per class i suppose?
What if for tha same class you have 2 or more rows with same max date?
Please.... be more specific, even the result seems to be obvious.
------------
When you 've got a hammer, everything starts to look like a nail...
April 6, 2006 at 6:51 am
I understand the question but why must it be without a sub-query? Seems like a very unnecessary limitation unless you're doing this in an early version of MySQL or something similar.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply