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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sanjay5219
Posting Yak Master

240 Posts

Posted - 09/28/2012 :  13:45:16  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 09/28/2012 :  16:13:05  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000