From the course: SQL Practice: Updating Data with UPDATE Statements
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Updating data using subqueries - SQL Tutorial
From the course: SQL Practice: Updating Data with UPDATE Statements
Solution: Updating data using subqueries
(cheerful upbeat music) - [Instructor] In this challenge, you were asked to update the products table by setting the stock based on the quantity available in the inventory table. The key here was to use a subquery to pull in the relevant data from another table. Let's walk through the solution step by step. We start with the basic structure of the update statement, "UPDATE Products." This indicates that we're going to update data in the products table. Next, we need to set the stock column in the products table to the corresponding quantity from the inventory table. To achieve this, we use a subquery in the select clause. Next, we need to set the stock column in the products table to the corresponding quantity from the inventory table. To achieve this, we use a subquery in the set clause. Here's what's happening. The subquery, "SELECT Quantity FROM Inventory WHERE Inventory.ProductID = Products.ProductID" fetches the quantity from the inventory table where the product ID matches the…