I have a simple one column table with two values. I select it and concatenate values with distinct modifier but it just gets latest value. Am I in a misconception with DISTINCT?
DECLARE @table TABLE(Id int)
DECLARE @result VARCHAR(MAX) = ''
INSERT @table VALUES(1), (2)
SELECT
@result = @result + CAST( Id AS VARCHAR(10)) + ','
FROM
@table
SELECT @result --— output: 1,2,
-------same With distinct
SET @result = ''
SELECT DISTINCT @result = @result
+ CAST( Id AS VARCHAR(10)) + ','
FROM @table
SELECT @result --— expected output: 1,2, actual output: 2, why?