Skip to content
Advertisement

How to compare two sets

I need to get all aid‘s values which have cid != 40 and cid= 39 (many-to-many connection)

I’ve prepared two queries but i don’t know how to except second from first

enter image description here

Advertisement

Answer

It looks like you’re actually pretty close, is this what you’re looking for?


Alternatively, you can do it without subqueries like so:

Though, this assumes there can only be single entries for 39 and 40 for a given aid value. For example if there were two entries with aid=1 and cid=39, and none with cid=4, aid=1 would not appear (because the sum would be 2). Similarly, an aid with two 39’s and one 40 would also be included in the results.


A third option involves a JOIN

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement