Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SELEZIONA DISTINTO su una colonna

Supponendo che utilizzi SQL Server 2005 o versioni successive, puoi utilizzare un CTE con ROW_NUMBER():

SELECT  *
FROM    (SELECT ID, SKU, Product,
                ROW_NUMBER() OVER (PARTITION BY PRODUCT ORDER BY ID) AS RowNumber
         FROM   MyTable
         WHERE  SKU LIKE 'FOO%') AS a
WHERE   a.RowNumber = 1