do not repeat table results

4

I have the following query

SELECT DISTINCT
HPNESTANC.ADNINGRES AS ESTANCIA1 , HPNESTANC.HESFECING AS FECHA_INGRESO  FROM HPNESTANC
 WHERE EXISTS
 (SELECT  MAX( HPNESTANC.ADNINGRES), MAX(HPNESTANC.HESFECING) FROM HPNESTANC WHERE  HPNDEFCAM IN(80,237, 238,239,240,241,242,243,244,
245,247,248,249,245,247,248,249,250,251,252,253,254,255,256,257,256,357)
 )ORDER BY 1

but I do not want to repeat those values in the result, the capture is the following:

    
asked by Rafael 03.07.2018 в 22:38
source

1 answer

1

Assuming that the query that you currently have is correct, you only have to use it as an entry for another query that brings together and brings the maximum date.

Select ESTANCIA1, Max(FECHA_INGRESO)
from (tu select)
group by ESTANCIA1

You could not do a select is select, doing the following:

SELECT 
HPNESTANC.ADNINGRES AS ESTANCIA1 , max(PNESTANC.HESFECING) AS FECHA_INGRESO  FROM HPNESTANC
 WHERE EXISTS
 (SELECT  MAX( HPNESTANC.ADNINGRES), MAX(HPNESTANC.HESFECING) FROM HPNESTANC WHERE  HPNDEFCAM IN(80,237, 238,239,240,241,242,243,244,
245,247,248,249,245,247,248,249,250,251,252,253,254,255,256,257,256,357)
 )
group by HPNESTANC.ADNINGRES 
ORDER BY 1
    
answered by 04.07.2018 / 00:02
source