-1

Good morning forum.

I have this basic query in oracle

SELECT P.IDPROYECT, P.NOPROGRAM, P.IDETAP, P.STATUS_ETAP, P.VERSION
FROM poa.PROYECT P
LEFT JOIN DGI.DEPENDENCIA UA ON (P.RAM = UA.RAM AND P.DEPT = UA.DEPT AND UA.YEAR = 2021);

I am attracted to a series of records so the noprogram is repeated 3 times but the only thing different is that the version of those 3 is newer, I would like it to show me only 1 of the 3 records that has a higher version

enter image description here enter image description here

MT0
  • 143,790
  • 11
  • 59
  • 117

1 Answers1

0

Use row_number as follows:

select * from
(SELECT P.IDPROYECT, P.NOPROGRAM, P.IDETAP, P.STATUS_ETAP, P.VERSION,
       ROW_NUMBER() OVER (PARTIRION BY P.NOPROGRAM ORDER BY P.VERSION DESC) AS RN
  FROM poa.PROYECT P
  LEFT JOIN DGI.DEPENDENCIA UA
    ON (P.RAM = UA.RAM AND P.DEPT = UA.DEPT AND UA.YEAR = 2021)
) Where rn = 1
Popeye
  • 35,427
  • 4
  • 10
  • 31