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.
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---enddate1-------2----------010120051-------4----------010120061-------7----------10012006I want the result to give me the most recent orgid, parentid. I tried using: "select orgid, parentid, max(enddate)enddate from aim_agent_team_factgroup 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 itselect orgid , (select parentid from aim_agent_team_fact t2 where t2.orgid = t1.orgid and t2.enddate = max(t1.enddate)) parentid , max(enddate) enddatefrom aim_agent_team_fact t1group by orgid |
 |
|
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-10-18 : 17:41:21
|
That worked perfectly!! Thanks much snSQL!!! |
 |
|
|
|
|