The easy way to do it for your sample data is with NOT IN
:
SELECT *
FROM set_t
WHERE set_r NOT IN ('a', 'b', 'a,b')
But this does not scale well if you have larger set and you want to include more members than a
and b
in the list of known members.
Every member of a set is stored as a numeric value.
In your set the numeric values are:
SET Member Decimal Value Binary Value
'a' 1 001
'b' 2 010
'c' 4 100
So, a value like 'a,b'
is stored as 3
(Binary 011
)
and a value like 'a,b,c'
is stored as 7
(Binary 111
)
If you know the numeric values of the known members, which you can get by the order they are defined in the set, then you can use bit operations to get what you want:
SELECT *
FROM set_t
WHERE set_r | 3 <> 3 -- 3 is the numeric value of 'a,b'
or:
SELECT *
FROM set_t
WHERE set_r | 0b11 <> 0b11 -- 0b11 is the numeric binary value of 'a,b'
See the demo.