Please use the below code..DECLARE @Input TABLE(sttckt INT, sttot INT, stdescr VARCHAR(20))INSERT INTO @Input VALUES (123, 0, 'coca cola'),(123, 20, 'freight'),(123, 0, 'coca cola'), (124, 10, 'pepsi'), (124, 0, 'freight'), (124, 0, 'pepsi'),(125, 1, 'abcd')SELECT DISTINCT sttckt, stdescr FROM @Input t1WHERE stdescr <> 'freight'AND EXISTS (SELECT 1 FROM @Input t2 WHERE t2.sttckt = t1.sttckt AND t2.stdescr = 'Freight')
Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.