Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Databases > Re: group by pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 314 of 387
Post > Topic >>

Re: group by problem in access

by Lemming <thiswillbounce@[EMAIL PROTECTED] > Oct 4, 2005 at 06:15 PM

On Tue, 27 Sep 2005 20:04:34 +0100, <jim> wrote:

>hi,
>
>i have a table( tblUpdate) with the following fields
>
>UpdateID, UpdateDate,  ActionID
>
>UpdateID is the primary key
>ActionID is a foreign key
>
>i want to find the latest (by date) update of a particluar action.
>
>and i can do this using the following:
>
>SELECT Max(tblUpdate.UpdateDate) AS MaxOfUpdateDate, tblUpdate.ActionID
>FROM tblUpdate
>GROUP BY tblUpdate.ActionID;
>
>
>this gives me :
>
>"MaxOfUpdateDate","ActionID"
>24/9/2005 ,24
>26/8/2005 ,25
>11/9/2005 ,26
>26/9/2005 ,28
>
>which is good but i also need the primary key, UpdateID
>
>If i add updateID into the query  i get
>
>SELECT Max(tblUpdate.UpdateDate) AS MaxOfUpdateDate, tblUpdate.UpdateID, 
>tblUpdate.ActionID
>FROM tblUpdate
>GROUP BY tblUpdate.UpdateID, tblUpdate.ActionID;
>
>i now get this
>
>"MaxOfUpdateDate","ActionID","UpdateID"
>24/9/2005 ,24,23
>22/9/2005 ,24,24
>26/8/2005 ,25,25
>26/9/2004 ,25,26
>11/9/2005 ,26,27
>26/9/2005 ,28,28
>
>which is no good because im getting results for all the updateids
>
>i really just want :
>
>"MaxOfUpdateDate","ActionID"
>24/9/2005 ,24
>26/8/2005 ,25
>11/9/2005 ,26
>26/9/2005 ,28
>
>but with the primary key for each one.
>
>any help would be much appreciated

How about this - just knocked together quickly in the QBE and not
thoroughly tested:

SELECT 
	 tblUpdate.UpdateId
	,tblUpdate.ActionId
	,tblUpdate.UpdateDate
FROM
	 tblUpdate 
INNER JOIN 
	tblUpdate AS tblUpdate_1 
ON 
	tblUpdate.ActionId = tblUpdate_1.ActionId
GROUP BY 
	 tblUpdate.UpdateId
	,tblUpdate.ActionId
	,tblUpdate.UpdateDate
	,tblUpdate_1.ActionId
HAVING 
	(((tblUpdate.UpdateDate)=Max([tblUpdate_1].[UpdateDate])));

With this data:

UpdateId	ActionId	UpdateDate
1			24			24/12/2004
2			16			13/06/2005
3			44			21/06/2004
4			18			22/04/2004
5			11			14/09/2005
6			11			14/05/2005
7			24			12/05/2004

This query gives:

UpdateId	ActionId	UpdateDate
1			24			24/12/2004
2			16			13/06/2005
3			44			21/06/2004
4			18			22/04/2004
5			11			14/09/2005

Is that what you need?

Lemming
-- 
Curiosity *may* have killed Schrodinger's cat.
 




 2 Posts in Topic:
group by problem in access
<jim>   2005-09-27 20:04:34 
Re: group by problem in access
Lemming <thiswillbounc  2005-10-04 18:15:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 21:28:50 CST 2008.