Thursday, September 20, 2012

SQL Update with inner joins


Important points in SQL Update:

(1) We can not update more than one table at a time.

Customer places an Order

(2) We can use INNER JOIN with UPDATE in following way (w.r.t database schema above):

UPDATE Ref_Order_Status_Codes
SET 
order_status_description = 'Paid'

FROM Products AS PROD


INNER JOIN Customer_Orders_Products AS CUST_PROD ON PROD.product_id = CUST_PROD.product_id

INNER JOIN Customer_Orderss AS CUST_ORD ON CUST_PROD.order_id = CUST_ORD.order_id
INNER JOIN Ref_Order_Status_Codes AS REF ON REF.order_status_code = CUST.order_status_code

WHERE PROD.product_id = 'WKSO00045'



No comments:

Post a Comment