Sample for 9132209 Not Exists

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

Declare @table table (ID1 int, ID2 int, Num INT, Type char(1))

INSERT INTO @table 
VALUES 
 (1,     1,     1,    'A'),
 (1,     1,     2,    'A'),
 (1,     2,     3,    'A'),
 (1,     2,     4,    'A'),
 (2,     1,     1,    'A'),
 (2,     2,     1,    'B'),
 (3,     1,     1,    'A'),
 (3,     2,     1,    'A')


SELECT DISTINCT t1.ID1, t1.ID2 
FROM
    @table  t1

WHERE
    t1.Type = 'A'
AND
NOT EXISTS 
(SELECT 1 FROM @table t2 WHERE t1.ID1 = t2.ID1 AND Type <> 'A')

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached