WITH cte as (--cte is your test data SELECT 1 id, 50 value UNION SELECT 2, 50 UNION SELECT 3, 50 UNION SELECT 4, 52 UNION SELECT 5, 50 UNION SELECT 6, 30 UNION SELECT 7, 30 UNION SELECT 8, 35 UNION SELECT 9, 30 UNION SELECT 10, 30 UNION SELECT 11, 60 UNION SELECT 12, 65 UNION SELECT 13, 60 UNION SELECT 14, 60 ), temp AS --temp numbers the rows ( SELECT id, value, ROW_NUMBER() OVER (ORDER BY id) rowno FROM cte ) SELECT t2.value FROM temp t1 INNER JOIN temp t2 ON t1.rowno = t2.rowno - 1 --join to the next row using rownumber AND t1.value <> t2.value --but only return different values
Colin
source share