Exclude certain results from in condition in sql
One way to get the results you're after is to &quot;reverse&quot; both the EXISTS and IN operators - it's a little confusing to read, though.  I also got rid of the distinct, since it's not really needed in the subquery.
SELECT * 
FROM #Table1
WHERE NOT EXISTS 
(
    SELECT ID 
    FROM #Table2 
    WHERE
        #Table1.ID = #Table2.ID 
        AND WFID NOT IN (12,17)
);


Here's the setup for the query I'm using locally:
CREATE TABLE #Table1
(
    Id int NOT NULL,
    data1 varchar(2) NOT NULL,
    data2 varchar(3) NOT NULL
);
INSERT INTO #Table1
    (Id, data1, data2)
VALUES
    (1,  'ff',   'ffe'),
    (2,  'r' ,   '3'  ),
    (3,  'df',   'er' );

CREATE TABLE #Table2
(
    Id int NOT NULL,
    WFID int NOT NULL,
    data1 varchar(2) NOT NULL,
    data2 varchar(3) NOT NULL
);
INSERT INTO #Table2
    (Id, WFID, data1, data2)
VALUES
    (1,    12,    'd',     'e' ),
    (1,    13,    '3',     '4f'),
    (1,    15,    'e',     'dd'),
    (2,    12,    'f',     'ee'),
    (3,    17,    'd',     'f' );