using DISTINCT how can I check several records in a table? [closed]

-1

I have the following query

SELECT IdOcupacion, Codigo, Descripcion
FROM Ocupaciones

On which in the field of Descripcion I see several double registers and I would like to know how to consult only one of the registers but bring me the fields of idOcupacion and% Codigo of the occupation. thanks

    
asked by Daniel Soto 30.11.2017 в 15:50
source

2 answers

-2

Try this, I hope it works for you

SELECT IdOcupacion, Codigo, Descripcion
FROM Ocupaciones where IdOcupacion = /*Al codigo de ocupacion que deseas ver*/
    
answered by 30.11.2017 / 16:23
source
1

You still do not explain how to choose one record over the other, but hey, you can modify the following query to get it:

WITH CTE AS
(
   SELECT IdOcupacion, 
          Codigo, 
          Descripcion,
          RN = ROW_NUMBER() OVER(PARTITION BY Codigo, Descripcion 
                                 ORDER BY IdOcupacion)
   FROM Ocupaciones
)
SELECT *
FROM CTE 
WHERE RN = 1;
    
answered by 30.11.2017 в 17:02