T
Techno_Dex
Unfortunately I have been away from advanced SQL queries for to long and
have lost some of my knowledge. I'm hoping someone might be able to help me
recover this knowledge. I have a .NET 2.0 App using the Enterprise Library
(Connection String used Jet DB Engine). I have a table that I would like to
do a group by on two fields, then extract the top 1 record from each group
(using an order by clause to get the desire record to top the top of each
group). I have racked my brain on INNER JOINs, OUTER JOINs, DISTINCTS,
MAX() but can't come up with the solution.
What I have is a Table "XDocs" which has a Primary Key of ID, a field called
GroupID and a field called Version (other fields are in the table also)
ID GroupID Version Name
--- ---------- --------- --------
1 XA1 0 Document1
2 XA1 1 Document1
3 XA2 0 Document2
4 XA2 1 Document2
5 XA2 2 Document2
6 XA3 0 Document3
7 XA3 1 Document3
8 XA3 2 Document3
9 XA4 0 Document4
Results I would like are below. I want to group by GroupID and Version
ORDER BY GroupID, Version DESC (i.e.
SELECT GroupID, Version FROM XDocs GROUP BY GroupID, Version)
ID GroupID Version Name
--- ---------- --------- --------
2 XA1 1 Document1
5 XA2 2 Document2
8 XA3 2 Document3
9 XA4 0 Document4
have lost some of my knowledge. I'm hoping someone might be able to help me
recover this knowledge. I have a .NET 2.0 App using the Enterprise Library
(Connection String used Jet DB Engine). I have a table that I would like to
do a group by on two fields, then extract the top 1 record from each group
(using an order by clause to get the desire record to top the top of each
group). I have racked my brain on INNER JOINs, OUTER JOINs, DISTINCTS,
MAX() but can't come up with the solution.
What I have is a Table "XDocs" which has a Primary Key of ID, a field called
GroupID and a field called Version (other fields are in the table also)
ID GroupID Version Name
--- ---------- --------- --------
1 XA1 0 Document1
2 XA1 1 Document1
3 XA2 0 Document2
4 XA2 1 Document2
5 XA2 2 Document2
6 XA3 0 Document3
7 XA3 1 Document3
8 XA3 2 Document3
9 XA4 0 Document4
Results I would like are below. I want to group by GroupID and Version
ORDER BY GroupID, Version DESC (i.e.
SELECT GroupID, Version FROM XDocs GROUP BY GroupID, Version)
ID GroupID Version Name
--- ---------- --------- --------
2 XA1 1 Document1
5 XA2 2 Document2
8 XA3 2 Document3
9 XA4 0 Document4