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 |
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-10-30 : 14:58:00
|
Hi All,I have two tables T1 and T2T1 is having User : Visiting DateT2 IS having User : Last Visited DateNow I have to update T2 with last visited date based on T1 Entry.Please suggest the query |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-10-30 : 15:03:27
|
you mean this?update t2 set t2.lastVisitDate = d.MaxVDfrom ( select user, max(VisitDate) maxVD from T1 group by user ) dinner join T2 on t2.user = t1.userwhere t2.lastVisitDate != d.MaxVD If you also need to insert new Users to T2 then you may want to look at a MERGE statement.Be One with the OptimizerTG |
|
|
|
|
|