Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    207
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Last SQL question, I promise (for today, lol)

    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:
    Code:
    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!
    Website: www.billboardfamily.com
    Twitter: www.twitter.com/billboardfamily
    Facebook Fan Page: www.facebook.com/BillboardFamily
    Facebook (Carl): www.facebook.com/CarlMartin.BillboardFamily (admin note: sig should be <=4 lines)

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    SELECT Products.ProductName
    FROM Products where Products.ProductID not in (select ProductID from [Order Details])
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    207
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Code:
    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
    Website: www.billboardfamily.com
    Twitter: www.twitter.com/billboardfamily
    Facebook Fan Page: www.facebook.com/BillboardFamily
    Facebook (Carl): www.facebook.com/CarlMartin.BillboardFamily (admin note: sig should be <=4 lines)

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Don't use = with NULLs. A NULL is not equal to anything, including other NULLs.

    Use:
    Code:
    WHERE [Order Details].Quantity = NULL
    for example.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •