-4

The question I'm trying to answer is

Write a SELECT statement that returns the CategoryName column from the Categories table. Return one row for each category that has never been assigned to any product in the Products table. To do that, use a subquery introduced with the NOT EXISTS operator.

The Categories table includes the columns: CategoryID and CategoryName

The Products table includes the columns: ProductID,CategoryID,ProductCode,ProductName,Description,ListPrice,DiscountPercent,DateAdded

This is what I've tried:

SELECT CategoryName
From Categories
Where NOT EXISTS(SELECT CategoryID FROM Products WHERE CategoryID IS NOT NULL)

Anything helps, thanks!

5
  • You need to show some attempt and tell us where you have been struck Aug 2, 2015 at 1:49
  • The answer looks like this. Aug 2, 2015 at 1:50
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself.
    – Bond
    Aug 2, 2015 at 1:52
  • @Bond: The correct close reason for this question would be "too broad" since no code was provided and OP wants the complete solution.
    – juergen d
    Aug 2, 2015 at 1:54
  • @juergend: Perhaps. The "cannot figure out" in the title lead me to believe he must have tried something.
    – Bond
    Aug 2, 2015 at 1:57

1 Answer 1

0

I believe I got it to work with the following code:

SELECT CategoryName
From Categories
Where NOT EXISTS(SELECT CategoryID FROM Products)

It returned the desired results and fit the critiria of the question. Thanks anyway guys!

Not the answer you're looking for? Browse other questions tagged or ask your own question.