I have a scenario wherein I need to find the ID which only has start and END in it. Below is the table for reference.
Declare @T Table ( ID int, Name varchar(100))
Insert into @T values (1,'Start')
Insert into @T values (1,'END')
Insert into @T values (1,'Stuart')
Insert into @T values (1,'robin')
Insert into @T values (2,'Start')
Insert into @T values (2,'END')
Insert into @T values (3,'Start')
Insert into @T values (4,'END')
I want the Output as:
ID Name
2 Start
2 END
I want those ID which only has start and end in it.
What I tried so far:
SELECT * FROM @T t
WHERE EXISTS (SELECT * FROM @T WHERE id = t.id AND name = 'start')
AND EXISTS (SELECT * FROM @T WHERE id = t.id AND name = 'END')
But my query is giving ID 1 as well.
Can someone please help me rectify the problem.