select *
from @tmp a
WHERE NOT EXISTS (SELECT *
FROM @tmp b
WHERE b.Summary = a.Summary
AND b.type = 'MSG')
select query
Spunny
366
Reputation points
declare @tmp table
(
id INT IDENTITY(1,1),
Summary varchar(500),
type varchar(10),
filename varchar(500)
)
INSERT INTO @tmp
select 'xxx', 'PDF', 'FileName1'
union all
select 'yyy', 'PDF', 'FileName2'
union all
Select 'yyy', 'MSG', 'filename3'
union all
select 'zzz', 'PDF', 'filename4'
union all
select 'zzz', 'PDF', 'filename5'
select * from @tmp
I need to get a result of id 1, 4, 5
if there is any summary that has msg record, that shouldn't be output
TIA
SQL Server | SQL Server Transact-SQL
1 answer
Sort by: Most helpful
-
Erland Sommarskog 127.7K Reputation points MVP Volunteer Moderator2025-09-05T21:47:36.43+00:00