samedi 25 juin 2016
Subquery in IN does not work
I'm using TransactSQL (Microsoft SQL Server 2014) and here's my problem:
I'm using the standard "Northwind" database for practice and I wanted to see a list of Categories that don't have any Products.
Firstly I created a new Category, which wouldn't have any Products:
insert into Categories (CategoryName) values ('TestCategory')
Then I wrote this:
SELECT CategoryName
FROM Categories
WHERE CategoryID NOT IN (select CategoryID from Products)
Unfortunately it gives nothing.
Here's how I understand it:
I want to find categories without products connected with them, so I used
WHERE CategoryID NOT IN (select CategoryID from Products), because I want to compare every CategoryID from Categories table with a list which I get from select CategoryID from Products - this list includes every category that HAS products. So I think that using NOT IN should let me to see categories that don't have any products.
I hope you understood what I was trying to describe. It would be great if you could help.
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire