diff --git a/SQL_exercise_01/1_questions_and_solutions.sql b/SQL_exercise_01/1_questions_and_solutions.sql index d676e41..7e04f81 100644 --- a/SQL_exercise_01/1_questions_and_solutions.sql +++ b/SQL_exercise_01/1_questions_and_solutions.sql @@ -90,22 +90,17 @@ ORDER BY price ASC -- 1.16 Select the name of each manufacturer along with the name and price of its most expensive product. -select max_price_mapping.name as manu_name, max_price_mapping.price, products_with_manu_name.name as product_name -from - (SELECT Manufacturers.Name, MAX(Price) price - FROM Products, Manufacturers - WHERE Manufacturer = Manufacturers.Code - GROUP BY Manufacturers.Name) - as max_price_mapping - left join - (select products.*, manufacturers.name manu_name - from products join manufacturers - on (products.manufacturer = manufacturers.code)) - as products_with_manu_name - on - (max_price_mapping.name = products_with_manu_name.manu_name - and - max_price_mapping.price = products_with_manu_name.price); +SELECT Products.Name as "Products Name", +Products.Price as "Price", +Manufacturers.Name as "Manufacture Company" +from Products,Manufacturers +where Products.Manufacturer = Manufacturers.Code +and Products.Price = +( +select max(Products.Price) +from Products +where Products.Manufacturer = Manufacturers.Code +);