By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tab(
ID INT,
Colors_Allowed VARCHAR(30)
);
INSERT INTO tab VALUES
(555, 'Blue'),
(555, 'Green' ),
(666, 'Blue'),
(786, 'Blue'),
(888, 'Blue'),
(888, 'Green'),
(888, 'Red'),
(999, 'Red'),
(999, 'Orange');
SELECT * FROM tab
ID | Colors_Allowed |
---|---|
555 | Blue |
555 | Green |
666 | Blue |
786 | Blue |
888 | Blue |
888 | Green |
888 | Red |
999 | Red |
999 | Orange |
SELECT t1.*
FROM tab t1
WHERE NOT EXISTS(SELECT 1
FROM tab t2
WHERE t1.ID = t2.ID AND colors_allowed = 'Green')
ID | Colors_Allowed |
---|---|
666 | Blue |
786 | Blue |
999 | Red |
999 | Orange |