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 2000 Forums
 Transact-SQL (2000)
 update query with inner join

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-09-21 : 07:19:39
Yoni writes "Hi All

Please provide SQL query syntax for the following:

Copy TableA.Usernames from TableA to TableB for all records where TableA.LastName = TableB.LastName

Thank you.

Yoni"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-09-21 : 07:21:45
INSERT INTO TableB
SELECT A.*
FROM TableA A INNER JOIN TableB B ON A.LastName=B.LastName


Don't know why you want to copy rows that already exist in the table, but that should do it.

Hope you get a good score on the test.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-21 : 07:22:14
Try this

Update T2 set T2.UserName=T1.UserName from TableA T1 inner join TableB T2 on T1.LastName = T2.LastName


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-09-21 : 08:01:06
Wow, did I misread that question. Never mind, pretend I wasn't here.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-21 : 08:11:21
May be you are busy with thinking something else

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -