Q&A about the site for enthusiasts and scholars of mythology and folklore
DECLARE @mytable TABLE ([userid] integer, [outcome] varchar(max), id integer) INSERT INTO @mytable VALUES (101, 'start', 1), (101, 'sold', 2), (101, 'return', 3), (101, 'sold', 4), (102, 'start', 1), (102, 'call', 2), (102, 'mailer', 3), (102, 'sold', 4), (102, 'return', 5), (103, 'start', 1), (103, 'mailer', 2) SELECT t.* FROM @mytable t INNER JOIN (SELECT userid uid, MIN(id) sid FROM @mytable WHERE outcome='sold' GROUP BY userid) s ON uid=userid AND sid>=id