Update records in one table based on values in another table SQL Server
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?
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
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!