Update records in one table based on values in another table SQL Server

57
Views
1
Answers

I need to update records in one table based on values in another table. i.e I need to match, say Customer_id in Customers table with the Supplier_id in Supplier table and update Supplier table column "City" with the values from the Customer table column "City". How to do this?

edit | flag
William Patrick
Asked on: Jun 28, 2011 at 12:43AM

1 Answers

41
4
41

You can use this Query..

UPDATE suppliers      
SET city
=     ( SELECT customers.city
FROM customers
WHERE customers
.customer_id = suppliers.supplier_id)
WHERE EXISTS
 
( SELECT customers.city
    FROM customers
    WHERE customers
.customer_id= suppliers.supplier_id);
edit | flag
Gokul A
Answered on: Jun 28, 2011 at 12:45AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags