Need assistance with Oracle query , Identify documents which is not accessed between the date provided and show only one latest action on document (either view, fetch, reserve, which is mentioned by AuditID in below query) -
I have the query prepared its returning data but for some dates its not returning valid data - please assist.
Below is the query I have written..
SELECT dt.dataid "Data ID", dt.name "Document Name", kt.LastName "Last Name", kt.FirstName "First Name", DA.AUDITSTR "Acess Description" FROM dtree dt, dauditnew da, kuaf kt
WHERE dt.dataid = da.dataid
AND kt.id = da.PERFORMERID
AND da.auditid IN (1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 14, 15, 23, 25, 26, 28, 34, 35, 173, 174, 636002, 636003)
AND da.auditdate BETWEEN to_date('01-Sep-2000', 'dd-mon-yyyy HH:MI:SS') AND to_date('01-Sep-2016', 'dd-mon-yyyy HH:MI:SS')
AND da.auditdate = (SELECT MAX(da2.auditdate) FROM dauditnew da2, dtree dt2 WHERE dt2.dataid = da2.dataid AND dt2.name = dt.name GROUP BY dt2.name)
AND dt.DATAID IN (SELECT DATAID FROM DTREE START WITH DATAID = '7547034' CONNECT BY PRIOR DATAID = PARENTID)
With this query, I am getting multiple hits for the same document like Fetch, Reserve and View document type. I need to get latest action lets say - if Fetch is the last happened for that particular document then that should be shown ONLY, ignoring other 2 actions. So, I need to get latest list of documents for the given date with last action.