-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!

OysterMaker
  • 279
  • 2
  • 13
  • 26
  • You need to show some attempt and tell us where you have been struck – Pரதீப் Aug 02 '15 at 01:49
  • The answer [looks like this](http://stackoverflow.com/questions/11948549/how-select-for-not-used-codes-in-this-sample). – Clockwork-Muse Aug 02 '15 at 01: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 02 '15 at 01: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 02 '15 at 01:54
  • @juergend: Perhaps. The _"cannot figure out"_ in the title lead me to believe he must have tried something. – Bond Aug 02 '15 at 01:57

1 Answers1

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!

OysterMaker
  • 279
  • 2
  • 13
  • 26