|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Get the latest date for each IDHello,
I'm using SQL 2000. I have a table with an ID and dates plus other fields. I was trying to get the latest date for each ID. I tried a simple grouping asking for the MAX(Date) and I still get all the dates. I tried writing a nested query and still get the same answers. For example, if you have a list of books and you wanted the latest publication date for each edition of those books, how would you go about doing that. -- Brandon H. Campbell Systems Analyst Database Administrator SELECT ID, MAX(Date)
FROM table GROUP BY ID Show quote "Brandon H. Campbell" <BrandonHCampb***@discussions.microsoft.com> wrote in message news:8C9150DA-BB15-4DC3-B760-5AFFC1636562@microsoft.com... > Hello, > > I'm using SQL 2000. > > I have a table with an ID and dates plus other fields. > > I was trying to get the latest date for each ID. I tried a simple grouping > asking for the MAX(Date) and I still get all the dates. I tried writing a > nested query and still get the same answers. > > For example, if you have a list of books and you wanted the latest > publication date for each edition of those books, how would you go about > doing that. > -- > Brandon H. Campbell > Systems Analyst > Database Administrator > Thank you very much.
I made the mistake of including the date in the group by clause. I'm not having a great mental day. -- Show quoteBrandon H. Campbell Systems Analyst Database Administrator "Aaron Bertrand [SQL Server MVP]" wrote: > SELECT ID, MAX(Date) > FROM table > GROUP BY ID > > > "Brandon H. Campbell" <BrandonHCampb***@discussions.microsoft.com> wrote in > message news:8C9150DA-BB15-4DC3-B760-5AFFC1636562@microsoft.com... > > Hello, > > > > I'm using SQL 2000. > > > > I have a table with an ID and dates plus other fields. > > > > I was trying to get the latest date for each ID. I tried a simple grouping > > asking for the MAX(Date) and I still get all the dates. I tried writing a > > nested query and still get the same answers. > > > > For example, if you have a list of books and you wanted the latest > > publication date for each edition of those books, how would you go about > > doing that. > > -- > > Brandon H. Campbell > > Systems Analyst > > Database Administrator > > > > > Brandon H. Campbell wrote:
Show quote > Hello, http://www.realsqlguy.com/serendipity/archives/10-Gimme-The-Latest-And-Greatest!.html> > I'm using SQL 2000. > > I have a table with an ID and dates plus other fields. > > I was trying to get the latest date for each ID. I tried a simple grouping > asking for the MAX(Date) and I still get all the dates. I tried writing a > nested query and still get the same answers. > > For example, if you have a list of books and you wanted the latest > publication date for each edition of those books, how would you go about > doing that. |
|||||||||||||||||||||||