Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Max aggregate help

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2006-10-18 : 17:14:47
This may be more easier than it sounds but I just can't figure it out.

I have the following table:

orgid---parentid---enddate
1-------2----------01012005
1-------4----------01012006
1-------7----------10012006

I want the result to give me the most recent orgid, parentid. I tried using:

"select orgid, parentid, max(enddate)enddate from aim_agent_team_fact
group by orgid"

But it doesn't give me the correct info i'm looking for. Any help is always appreciated.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-18 : 17:37:46
This should do it

select orgid
, (select parentid from aim_agent_team_fact t2 where t2.orgid = t1.orgid and t2.enddate = max(t1.enddate)) parentid
, max(enddate) enddate
from aim_agent_team_fact t1
group by orgid
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2006-10-18 : 17:41:21
That worked perfectly!! Thanks much snSQL!!!
Go to Top of Page
   

- Advertisement -