I have a table like this
AID B C
2471 D471 X
2471 D471 Y
2471 E471 X
2471 F471 Y
2472 D471 X
2472 D471 X
2473 E471 Y
2473 E471 Y
2474 F471 Y
I need to pick the AID which has either X or Y by grouping A and B, but it should not pick the records which have X as well as Y when we grouped by A and B
Expected Output
AID B C
2471 E471 X
2471 F471 Y
2472 D471 X
2472 D471 X
2473 E471 Y
2473 E471 Y
2474 F471 Y
If you have any questions about this query, please let me know.
Scripts to create a table and insert data
CREATE TABLE tablename
(
[A] int
, [B] varchar(10)
, [C] varchar(5)
);
INSERT INTO tablename
([A], [B], [C])
VALUES
(2471, 'D471', 'X'),
(2471, 'D471', 'Y'),
(2471, 'E471', 'X'),
(2471, 'F471', 'Y'),
(2472, 'D471', 'X'),
(2472, 'D471', 'X'),
(2473, 'E471', 'Y'),
(2473, 'E471', 'Y'),
(2474, 'F471', 'Y')
;