Jump to content

Syntax for opposite of "IN"


DaGeek

Recommended Posts

Sorry for being dumb, but I just can't figure this one out....

 

I have ONE table - categories.

 

It has two fields

 

itemno, category

 

An item number can have an entry for many categories, ie

 

Item #1, Category A

Item #1, Category B

 

Item #2, Category A

Item #2, Category B

Item #2, Category C

 

Item #3, Category B

Item #3, Category C

 

 

If I want a list of ALL items that are in Categroy B AND in Category C I would expect to get back just Item Numbers 2 and 3 because Item #1 does not have an entry for category C.

 

If I use "select * from categories where category in ('B','C')", I will also get Item #1 which I do NOT want.

 

 

Does anyone have a suggestion as to the syntax for returning all rows where there is an entry for B AND C?

 

TY Brian

Link to comment
Share on other sites

Check out my post at this link and the other thread that is linked to - http://www.phpfreaks.com/forums/index.php/topic,200503.0.html

 

You can use a HAVING cnt = 2 (cnt is the alias name for the count(*) value) to find things that are in exactly two different categories, or you can use HAVING cnt > 1 to find everything that appears in more than just one category.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.