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 |
|
sggy
Starting Member
8 Posts |
Posted - 2007-07-18 : 17:34:39
|
| Hi, I have the following task: table contains multiple records for same email address. i need to select a user with the latest createdate including his idTable-----email id FN LN CreateDatemail1 234 john stone 20070809mail1 432 john stone 20060809mail1 765 john stone 20050809i need to select mail1 234 (email and id) since CreateDate is the latest for this account. I cannot figure out how to do this in one query. For now i first group by mail and select max(createdate) into one table and then join two tables on mail and createdate and select id that corresponds to the latest createdate. Do you know how to assomplish this in one query?Thanks in advance, sggy |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-18 : 19:25:09
|
| [code]SELECT *FROM mail aINNER JOIN ( SELECT email, createdate = MAX(createdate) FROM mail GROUP BY email ) b ON a.email = b.email AND a.createdate = b.createdate[/code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-19 : 05:17:37
|
| orselect columns from mail M where creadtedate=(select max(createdate) from mail where name=M.name)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|