Use SQL Server DISTINCT Clause

0

Hello, I need some help! I need to do a query and bring the NIF's, without repeating. I do it like this:

SELECT DISTINCT NIF FROM CustomerRegistrations

But I want to bring in more columns from this table as well. But I can not do this:

SELECT DISTINCT NIF, Name, RegistrationDate FROM CustomerRegistrations

Because it will bring repeated NIF's. That is, there are NIF's with different names, but I just want to bring one. Thanks to those who help!

    
asked by anonymous 14.06.2017 / 16:35

1 answer

1

select distinct in temp table sql server

It's basically the same problem I had: the author of this code is @ joséDiz , I will modify it to meet your demand: br>

WITH Sinc_2
AS (SELECT*,
        seq = ROW_NUMBER() OVER (PARTITION BY NIF ORDER BY NIF)
        FROM CustomerRegistrations)
SELECT nomerepresentante, codigorepresentante, datasinc
FROM Sinc_2
WHERE seq = 1;

The more columns you put in PARTITION BY , the less distinction it will make

    
05.10.2018 / 18:36