Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am studying SQL from w3schools tutorial. It seems there example on ALL keywords is incorrect. I just want to confirm whether the example is wrong there or am no getting it?

SELECT ProductName FROM Products WHERE ProductID = ALL (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);

Code explanation:

Given SQL statement gives TRUE and lists out the productnames if ALL the records in the OrderDetails table has quantity = 10

What I get from it is , SELECT returns us all products ID that has orders with quantity equals to 10, therefore we have list of ID. 

I reported this as an error on their website but did not receive any answer. Kindly help me out with this. 

1 Answer

0 votes
by (11.7k points)

You are almost right because the explanation on their website is just confusing and incomplete.

Anyway, the query will return as:

  • The one productname if there is exactly one productid with a quantity of 10.

  • All the productnames if there are no productids available with a quantity.

Please also keep in mind that ALL also applies to an empty list. Therefore, any given ProductId is equal to all the ProductIds in an empty list -- even a NULL ProductId.

If you want to get more insights into SQL, checkout this SQL Course from Intellipaat.

Browse Categories

...