I have a database (NexusDB (supposedly SQL-92 compliant)) which contains and Item table, a Category table, and a many-to-many ItemCategory table, which is just a pair of keys. As you might expect, Items are assigned to multiple categories.
I am wanting to all the end user to select all items which are
ItemID | CategoryID
--------------------------------
01 | 01
01 | 02
01 | 12
02 | 01
02 | 02
02 | 47
03 | 01
03 | 02
03 | 14
etc...
I want to be able to select all ItemID's that are assigned to Categories X, Y, and Z but NOT assigned to Categories P and Q.
For the example data above, for instance, say I'd like to grab all Items assigned to Categories 01 or 02 but NOT 12 (yielding Items 02 and 03). Something along the lines of:
SELECT ItemID WHERE (CategoryID IN (01, 02))
...and remove from that set SELECT ItemID WHERE NOT (CategoryID = 12)
This is probably a pretty basic SQL question, but it's stumping me at the moment. Any help w/b appreciated.