<?php

SELECT *, mainTable.EMP_ID,CONCAT(FinancialYearFromDate(mainTable.FORTNIGHT),'_',FinancialYearToDate(mainTable.FORTNIGHT)) AS financialYear, (SELECT SubTable.FINAL_PAYABLE_VALUE FROM fort_night_claims AS SubTable WHERE SubTable.FROM_DATE < FinancialYearToDate(mainTable.FORTNIGHT) AND SubTable.EMP_ID=mainTable.EMP_ID ORDER BY SubTable.FROM_DATE DESC LIMIT 1 ) AS finalPaybleValue FROM fort_night_claims AS mainTable GROUP BY mainTable.EMP_ID,financialYear HAVING finalPaybleValue < 0
?>