PDA

View Full Version : Last SQL question, I promise (for today, lol)


CarlMartin10
08-18-2010, 05:26 AM
I am trying to get better at using Joins, and I have gone through pretty far, but I am not having luck with this one. I am using a SQL book to learn this, and it is pretty good, but this one question tonight is not going so well. If you can help me out, thanks!

Here is the question in the book:

Generate a list of products (ProductName) that have never been ordered (outer join between [Order Details] and Products).

Here is my code as of now:
Use Northwind;
SELECT Products.ProductName
FROM Products LEFT OUTER JOIN [Order Details]
ON Products.ProductID =
[Order Details].ProductID
WHERE [Order Details].Quantity = NULL

This is returning no data at all. I have some thoughts as to why, but my other methods are not working too well!

abduraooft
08-18-2010, 06:38 AM
SELECT Products.ProductName
FROM Products where Products.ProductID not in (select ProductID from [Order Details])

CarlMartin10
08-18-2010, 06:40 AM
SELECT Products.ProductName
FROM Products where Products.ProductID not in (select ProductID from [Order Details])

That does not return anything at all, either...and, that does not use a Join, which is the point of the exercise. thanks though

abduraooft
08-18-2010, 07:07 AM
Take a look at http://planet.mysql.com/entry/?id=24888

guelphdad
08-18-2010, 02:12 PM
Don't use = with NULLs. A NULL is not equal to anything, including other NULLs.

Use:
WHERE [Order Details].Quantity = NULL

for example.