sql server database query remove duplicate data records

Question:
bloggers in June 2011, Guangdong Polytechnic Normal University senior, when seen from the school website EPRI meter jobs and Guangdong Centaline IT department interview, remember very clearly at the time of interview questions: how the database from inside query duplicate records.

Solution:
In sql server, you can use group by and having to solve the problem.

script:

/ * 
    Script Source: HTTPS: //www.cnblogs.com/zhang502219048/p/11100778.html 
* / 
the Create  the Table #t 
( 
    ID int 
) 

- ready to test data 
INSERT  INTO #t
 values ( 1 ), ( 2 ) , ( 3 ), ( 2 ), ( 1 ) 

- use group by and having recorded repeatedly query 
SELECT ID
 from #t
 Group  by ID
 HAVING  COUNT ( * ) >  1 

drop  Table #t

[Reserved Note Myung text Source: https://www.cnblogs.com/zhang502219048/p/11100778.html ]

 

Guess you like

Origin www.cnblogs.com/zhang502219048/p/11100778.html