I am sure it was asked before but I just can't figure out how to search for it
I have a table table1:
| RefId_1 | RefId_2 |
---------------------
| 1 | 133 |
| 3 | 12 |
| 4 | 144 |
| 4 | 22 |
| 3 | 123 |
I need to get list of RefId_1
which do have reference to list of RefId_2
but don't have any references to another list of RefId_2
.
For example, I need list of RefId_1
which references to RefId_2
list of (133, 22, 44) but such RefId_1
should not have references to list of RefId_2
(12, 144, 111).
Result should be just (1) because (4) references to forbidden 144
Thanks in advance
UPDATED : (UNTESTED)
SELECT DISTINCT REF_ID1 FROM table1
WHERE REF_ID2 IN(133,22,44)
AND
REF_ID1 NOT IN
(SELECT REF_ID1 FROM table1 WHERE REF_ID2 IN (12, 144, 111))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments