By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Create Table table_name(Identifier1 INT, Identifier2 INT, Identifier3 INT, code VARCHAR(50));
Insert Into table_name Values(3286,302231,93348,'S'),
(3286,311807,95112,'S'),
(3434,311620,95042,'S'),
(3540,311737,95074,'F'),
(3540,311738,95075,'F'),
(3553,311750,95085,'F'),
(3797,312153,95228,'P'),
(3797,312153,95229,'P'),
(4076,312506,95415,'F'),
(4211,312639,95508,'H'),
(4212,312641,95511,'H'),
(5316,343278,105219,'S'),
(5316,343279,105220,'S'),
(6679,368484,108922,'T'),
(6716,368538,108953,'F'),
(6716,368538,108954,'F'),
(7013,405341,121949,'S'),
(7013,405342,121950,'F'),
(7013,405345,121951,'F'),
(7242,405807,122004,'S'),
(7242,405807,122005,'S'),
(7242,405808,122006,'F');
22 rows affected
SELECT Identifier1, Identifier2, Identifier3, code
FROM table_name
WHERE Identifier1 IN (SELECT Identifier1 FROM table_name WHERE code='S')
Identifier1 | Identifier2 | Identifier3 | code |
---|---|---|---|
3286 | 302231 | 93348 | S |
3286 | 311807 | 95112 | S |
3434 | 311620 | 95042 | S |
5316 | 343278 | 105219 | S |
5316 | 343279 | 105220 | S |
7013 | 405341 | 121949 | S |
7013 | 405342 | 121950 | F |
7013 | 405345 | 121951 | F |
7242 | 405807 | 122004 | S |
7242 | 405807 | 122005 | S |
7242 | 405808 | 122006 | F |
SELECT Identifier1, Identifier2, Identifier3, code
FROM table_name T
WHERE EXISTS(SELECT 1 FROM table_name D
WHERE T.Identifier1 = D.Identifier1 AND D.code='S')
Identifier1 | Identifier2 | Identifier3 | code |
---|---|---|---|
3286 | 302231 | 93348 | S |
3286 | 311807 | 95112 | S |
3434 | 311620 | 95042 | S |
5316 | 343278 | 105219 | S |
5316 | 343279 | 105220 | S |
7013 | 405341 | 121949 | S |
7013 | 405342 | 121950 | F |
7013 | 405345 | 121951 | F |
7242 | 405807 | 122004 | S |
7242 | 405807 | 122005 | S |
7242 | 405808 | 122006 | F |