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 2005 Forums
 Transact-SQL (2005)
 Update query

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2012-09-28 : 13:45:16
Hi All,

I am having two tables T1 and T2

T1 is having Student_Id and Last_Exam_Date

T2 is having Student_Id and Exam_Date

Now i have to update T1 table with last Exam Date. Please suggest

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-28 : 16:13:05
sounds like this

UPDATE t1
SET t1.Last_Exam_Date = t2.MaxDate
FROM T1 t1
INNER JOIN (SELECT Student_Id,MAX(Exam_Date) AS MaxDate
FROM T2
GROUP BY Student_id
)t2
ON t2.Student_Id = t1.Student_Id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -