I'm going through the book and in Chapter 15 Updating sets of data, in the Problems for you to solve section there is the following problem:
"Set the retail price of accessories (category = 1) to the wholesale price of the highest-priced vendor plus 35 percent"
I'm a bit confused about why the author is giving this solution:
UPDATE Products
SET
RetailPrice = ROUND(1.35 * (
SELECT DISTINCT WholesalePrice
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber =
Products.ProductNumber
AND WholesalePrice = (
SELECT MAX(WholesalePrice)
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber =
Products.ProductNumber)),0)
WHERE RetailPrice < 1.35 * (
SELECT DISTINCT WholesalePrice
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber = Products.ProductNumber
AND WholesalePrice = (
SELECT MAX(WholesalePrice)
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber =
Products.ProductNumber)
LIMIT 1)
AND CategoryID = 1;
...instead of:
UPDATE Products
SET
RetailPrice = ROUND(1.35 * (SELECT MAX(WholesalePrice)
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber =
Products.ProductNumber),0)
WHERE RetailPrice < 1.35 * (SELECT MAX(WholesalePrice)
FROM Product_Vendors
WHERE Product_Vendors.ProductNumber =
Products.ProductNumber
LIMIT 1)
AND CategoryID = 1;
Both produce the same outcome, the same number of rows being affected in MySQL Workbench ...so why then? Thanks guys.