select parte,compania from(
select Parte, Compania, row_number() over(partition by parte,compania order by parte,compania) as rn
from partes_tmp
) t1 where rn=1
ejemplo:
Código SQL:
Ver originalCREATE TABLE #temp (
dato1 INT,
dato2 INT
)
INSERT INTO #temp VALUES (1,1)
INSERT INTO #temp VALUES (2,1)
INSERT INTO #temp VALUES (3,1)
INSERT INTO #temp VALUES (1,1)
INSERT INTO #temp VALUES (1,1)
INSERT INTO #temp VALUES (2,1)
SELECT dato1,dato2 FROM(
SELECT dato1,dato2,ROW_NUMBER() OVER(partition BY dato1,dato2 ORDER BY dato1,dato2) AS rn FROM #temp) t1 WHERE rn=1
Resultado:
1 1
2 1
3 1
solo 1 registro aunque haya repetidos :)