Below is a sub-query of a bigger query, what I am trying to do is to get last 5 documents sorted by SL_DT
in descending.
I always get an error that the right parenthesis is missing, I have also considered using row_number() over (order by pa.last_modified_date desc)
but it doesn't work.
SELECT REPLACE (
wm_concat( SL_TXN_CODE
|| ' - '
|| SL_NO
|| '('
|| SL_DT
|| ') - '
|| SUM (SL_QTY)),
',',
' ,'
)
FROM STK_LEDGER
WHERE ROWNUM <= 5
AND SL_ITEM_CODE =
(SELECT IDH_ITEM_CODE
FROM AA_ITEM_DEFINATION_HEAD
WHERE IDH_SUPP_BC_1 = '111' OR IDH_ITEM_CODE = '111')
AND SL_TXN_TYPE IN ('SARTN', 'GRN', 'LTRFI')
AND SL_LOCN_CODE NOT IN ('D2', 'D4', 'D5')
GROUP BY SL_TXN_CODE, SL_NO, SL_DT
ORDER BY SL_DT DESC
Please suggest the best way to sort SL_DT
in descending and getting the 5 records only. As you can see that I need all data in one single field.
The database is Oracle 10g.
Thanks in advance.