Query without repeating sql server

0

Someone can help me get a query without repeated data by "column", and try the famous DISTINCT but only remove the repeated fields of all the columns that you select, SELECT DISTINCT RUC, BUSINESS NAME , TRADENAME , HOME , TELEPHONE , email, web FROM TEMP What I need is to show me the fields without repeating depending on the ruc.

    
asked by Percy 03.03.2018 в 20:24
source

2 answers

0

It may be something like that what you want:

Select 
    ruc, 
    Max(RAZONSOCIAL) RAZONSOCIAL, 
    Max(NOMBRECOMERCIAL) NOMBRECOMERCIAL, 
    Max(DOMICILIO) DOMICILIO, 
    Max(TELEFONO) TELEFONO, 
    Max(email) email, 
    Max(web) web 
FROM TEMP 
GROUP BY ruc' 

Otherwise you should explain how the data in your table is, the primary key, the combinations of possible data, and things like that ...

    
answered by 05.03.2018 в 19:10
0
Select 
  ruc, 
  RAZONSOCIAL, 
  NOMBRECOMERCIAL,
  DOMICILIO, 
  TELEFONO, 
  email, 
  web , COUNT(*) 
FROM TEMP 
GROUP BY ruc, RAZONSOCIAL, NOMBRECOMERCIAL, DOMICILIO, TELEFONO, email, web 
HAVING  COUNT()>1

The field count(*) at the end of the selection, will show the number of records that have data in common (repeated records), in having I can condition show me for example having count(*)=1 those that are unique, having count(*)>1 those that are repeated more than once.

    
answered by 09.08.2018 в 19:22