Update Table Query to update data from another table directly

Suppose we have two tables names:
Tbl_Topics & Tbl_TeacherTopics having columns
MyTopic, TopicId, TopicName
TeacherTopicID, TopicId, TopicName
And we want to update Tbl_Topics Table from Tbl_TeacherTopics for given TeacherTopicID

Query:

UPDATE Tbl_Topics SET TopicID=TT.TopicID,TopicName=TT.TopicName FROM
(SELECT TopicID,TopicName FROM Tbl_TeacherTopics WHERE TeacherTopicID=1062)AS TT
WHERE Tbl_Topics.MyTopic='Lakhan Pal garg'

0 comments: