Dear MySql Expert,

I've to downgrade my mysql script from sub-query(ver 4x) --to-> non sub-query(ver 3.32)

I manage to changed below sub-query --> non subquery...

Sub-query
=========
Code:
$qsLeaveSUM = "SELECT *
               FROM LeaveSum
               WHERE (nEmpNo = $EmpNo) AND
                     (tYear In 
                        (SELECT MAX(tYear)
                         FROM LeaveSum
                         WHERE (nEmpNo = $EmpNo)))";
Non Sub-query
=============

Code:
$qsLeaveSumMaxYear = "SELECT MAX(tYear) as tYear
                      FROM LeaveSum
                      WHERE nEmpNo = $EmpNo";

$rsLeaveSumMaxYear = mysql_query($qsLeaveSumMaxYear) or die("Invalid query");
$rowLeaveSumMaxYear = mysql_fetch_array($rsLeaveSumMaxYear);

$qsLeaveSUM = "SELECT LeaveSum.*
	       FROM LeaveSum
	       WHERE (nEmpNo = $EmpNo) AND
                     (tYear = '$rowLeaveSumMaxYear[tYear]')";

$rsLeaveSUM = mysql_query($qsLeaveSUM) or die("Invalid query");
BUT, how to convert this subquery??

This query has 2 processes:-
1) Categories "nTotalDay" with a new field name, based on "nLeaveTypeNo"
2) SUM the new fields

Code:
SELECT nEmpNo,
       tYear,
       SUM(nAnnualTaken)  AS nAnnualTaken, 
       SUM(nMedicalTaken) AS nMedicalTaken,
       SUM(nUnpaid)       AS nUnpaid,
       SUM(nCarryFwd)     AS nCarryFwd, 
       SUM(nReplacement)  AS nReplacementTaken
FROM (
      SELECT LeaveDetail.nEmpNo,
             LeaveDetail.tYear,
             If(nLeaveTypeNo = 1, nTotalDay, 0)  AS nAnnualTaken,
             If(nLeaveTypeNo = 4, nTotalDay, 0)  AS nMedicalTaken,
             If(nLeaveTypeNo = 2, nTotalDay, 0)  AS nUnpaid,
             If(nLeaveTypeNo = 9, nTotalDay, 0)  AS nCarryFwd,
             If(nLeaveTypeNo = 10, nTotalDay, 0) AS nReplacement
      FROM LeaveDetail
      WHERE LeaveDetail.nEmpNo=$EmpNo AND
            LeaveDetail.tYear='$txtYear' AND
            LeaveDetail.nLeaveStatusId=2)
vLeaveDetail
GROUP BY nEmpNo,
         tYear
Any idea??

TIA

Regards.