Detta kommer att fungera:
CREATE TABLE #temp
(
Column1 CHAR(1) ,
Column2 CHAR(2)
);
INSERT INTO #temp ( Column1 ,
Column2 )
VALUES ( 'A', 'B' ) ,
( 'A', 'C' ) ,
( 'A', 'D' ) ,
( 'R', 'B' ) ,
( 'R', 'D' ) ,
( 'S', 'E' );
SELECT *
FROM #temp
WHERE Column1 IN ( SELECT Column1
FROM #temp
WHERE Column2 = 'D' );
DROP TABLE #temp;
Resultat:
+---------+---------+
| Column1 | Column2 |
+---------+---------+
| A | B |
| A | C |
| A | D |
| R | B |
| R | D |
+---------+---------+