Distinct needed immediately after SELECT
SELECT DISTINCT ItemId, Size FROM ItemTilesSizes
If you want it to apply only to Size , you need GROUP BY , and aggregate to determine which of the possible matching ItemId values ββshould be returned (the example below returns the largest)
SELECT MAX(ItemId) AS ItemId, Size FROM ItemTilesSizes GROUP BY Size
Although from the explanation in the comment, I would simply return this as the only set of column results and perform any necessary concatenation in your application. If you must do this in SQL, you can use the XML PATH
SELECT STUFF((SELECT ',' + LEFT(ItemId, 10) FROM ItemTilesSizes WHERE Size = '8x12' FOR XML PATH('')), 1, 1, '')
source share