Talk:SQL Exercises/The computer store

Problem with "sort first by price" exercise
Exercise "Select the name and price of all products with a price larger than or equal to $180, and sort first by price (in descending order), and then by name (in ascending order)."

shows an error saying that I can't sort by name. Probably needs different data type

Alternative Syntax that can be used to avoid the error :

ORDER BY Product.Price DESC, CAST(Product.Name AS nvarchar(50))

Exercise 1
"Select the names of all the products in the store." I think should be here: Select Distinct Name From Products;

Exercise "Select the name and price of the cheapest product." It can't be:

SELECT name,price FROM Products ORDER BY price ASC LIMIT 1

because what if we have more than one cheapest product. Thus only second solution is correct.

Problem with "most expensive product" exercise
The exercise "Select the name of each manufacturer along with the name and price of its most expensive product" doesn't work under MS Access, which yields the error "You tried to execute a query that does not include the specified expression 'Nam' as part of an aggregate function." I presume that refers to 'Products.Name', and indeed it works if I leave that out. SebastianHelm (discuss • contribs) 08:18, 30 December 2015 (UTC)

Typical error in exercise 15
Question is "Select the name and price of the cheapest product." and there is 2 suggestion which gives different answer, if there is more than one cheapest product. Talking mathematically, " SELECT Name, Price FROM Products WHERE Price = (SELECT MIN(Price) FROM Products);" is correct answer and sorting and choosing first one is not correct answer.

Below code also works correctly for this exercise: SELECT name, MIN(price) FROM Products;