Showing posts with label categories. Show all posts
Showing posts with label categories. Show all posts

Friday, March 23, 2012

Many to Many Question

SQL2000
I have 3 tables
Customers
TBL_Categories (Master Table of Categories)
CUS_Categories (Many-to-Many Table)
My Schema is something like this:
TBL_Categories
SysID
CategoryName
CUS_Categories
SysID
CategoryID (Sysid in TBL_Categories)
CustomerID
I am looking for a query that will give me a list of all Category Names that
do not exists in CUS_Categories for a specific customer.
i.e. SELECT CategoryName FROM TBL_Categories WHERE (no categories exists for
customer 1)
TIA
Tim Morrison
On Fri, 10 Dec 2004 10:24:40 -0600, Tim Morrison wrote:

>SQL2000
>I have 3 tables
>Customers
>TBL_Categories (Master Table of Categories)
>CUS_Categories (Many-to-Many Table)
>My Schema is something like this:
>TBL_Categories
> SysID
> CategoryName
>CUS_Categories
> SysID
> CategoryID (Sysid in TBL_Categories)
> CustomerID
>I am looking for a query that will give me a list of all Category Names that
>do not exists in CUS_Categories for a specific customer.
>i.e. SELECT CategoryName FROM TBL_Categories WHERE (no categories exists for
>customer 1)
Hi Tim,
SELECT CategoryName
FROM TBL_Categories
WHERE NOT EXISTS
(SELECT *
FROM CUS_Categories
WHERE CUS_Categories.CategoryID = TBL_Categories.SysID
AND CUS_Categories.CustomerID = 1)
(untested)
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)