I have subquery into a principal query, and i need the subquery return me only the last row of all results, but i can`t use "order by <field> desc " in the subquery because this return me an error, nither "fetch first 1 rows only" because this return a error too. Any sugestion?
this es the SQL...
this es the SQL...
Code:
SELECT
C.NOMBRE,V.COBJCOD,CS.DESC,V.CSUBCOD,
N.NOMBRE,CS.NIVEL,V.SUBLIBRO,
V.TSUBLIBRO,CS.CAT5COD,CAT7COD,
A.CODIGO,V.ANIO,M.codigo,V.MES,
sum(V.saldod),acumulado
FROM
QS36F.FIN0002M V
Inner Join
QS36F.V570010 S
on
(S.codigo=V.SUCCOD)
Inner Join
QS36F.V57CIA E
on
(S.CODEMP=E.codigo)
Inner Join
QS36F.V570909 C
on
(C.cuenta=V.COBJCOD)
Inner Join
QS36F.V570901 CS
on
(CS.UNEGCOD=V.UNEGCOD
and
CS.CSUBCOD=V.CSUBCOD
and
CS.COBJCOD=V.COBJCOD)
Inner Join
QS36F.NIVEL N
on
(CS.nivel=N.codigo)
Inner Join
QS36F.ANIO A
on
(A.codigo=V.anio)
Inner Join
QS36F.MES M
on
(M.codigo=V.mes)
WHERE
acumulado IN
(
///SUBQUERY
select
acumulado
from
QS36F.FIN0002M
// order by acumulado desc ( <-- this return a error)
)
AND
(E.codigo='E01')
AND
(A.codigo='2007' OR A.codigo='2006')
GROUP BY
C.nombre,V.COBJCOD,CS.DESC,
V.CSUBCOD,N.nombre,CS.nivel,
V.sublibro,V.TSUBLIBRO,CS.cat5cod,
CS.cat7cod,A.codigo,V.anio,
M.codigo,V.mes
ORDER BY
C.nombre,V.COBJCOD,CS.DESC,
V.CSUBCOD,N.nombre,CS.nivel, V.sublibro,
V.TSUBLIBRO,CS.cat5cod,CS.cat7cod,
A.codigo,V.anio,M.codigo,V.mes,acumulado
FETCH FIRST 80 ROWS ONLY
Comment