There are **duplicate records** Find duplicate records **based on ExtNum**. But check that only for records where **findduplicate=** **'Y'** *EDIT (changed in sample to bit value)* DECLARE @TestTable TABLE (vid int, NAME varchar(20), extnum int, findduplicate bit) INSERT INTO @TestTable (vid, NAME, extnum, findduplicate) VALUES (1, 'hhh', 11111, 1), (2, 'bbb', 22222, 0), (3, 'ccc', 4444, 0), (4, 'hhh', 11111, 0), (5, 'bbb', 22222, 0) ; So the **result should return**
VID NAME ExtNum 1 hhh 11111 4 hhh 11111 **FYI:-**
Though there are duplicates on the ExtgNum=22222, it should **not come in the result** set We should get **only** "11111" related supplier list