I am trying to match the records having MAX(WORKITEM_ID)
but some PROCESS_INSTANCE_ID
are not coming though they are present in WORKITEM
table.
select WI.WORKITEM_ID as WORKITEMID,
PI.PROCESS_INSTANCE_ID PIID,WS.WS_LABEL as WSNAME
from WORKITEM WI,PROCESSINSTANCE PI,TASKASSIGNMENT_V4TA,
SDI_WIDGET_WORKSTEP WS
where WS.WS_NAME = WI.WORKSTEP_NAME and
TA.PROCESS_INSTANCE_ID = PI.PROCESS_INSTANCE_ID and
PI.status in ('PI_ACTIVATED','PI_COMPLETED')and
WI.PROCESS_INSTANCE_ID = PI.PROCESS_INSTANCE_ID
and WI.status in ('I_ASSIGNED','I_AVAILABLE')
and WI.WORKITEM_ID =
(select MAX(WORKITEM_ID)from (select WITEM.WORKITEM_ID from WORKITEM WITEM
where **WITEM.PROCESS_INSTANCE_ID = WI.PROCESS_INSTANCE_ID**) as WORKITEMID)