SELECT p1.* FROM v_leave2 p1
INNER JOIN leave_doc p2 ON p1.doc_id = p2.running
WHERE p2.sys_checkdoc = '$CheckDoc'
AND p1.leave_status in ('Y','N') $strWhere
Group By p1.doc_id
Order By p1.leave_adjust desc, p1.doc_id
SELECT p1.* FROM v_leave2 p1
INNER JOIN leave_doc p2 ON p1.doc_id = p2.running
WHERE p2.sys_checkdoc = '$CheckDoc'
AND p1.leave_status in ('Y','N') $strWhere
Group By p1.doc_id
Order By p1.leave_adjust desc, p1.doc_id