My data loooks like this,
employeeSalaryId employeeId title value currency effectiveFrom
10 1000 Salary 22750.00 USD 2021-01-01
4 1000 Salary 19500.00 USD 2020-09-23
I want to return records based on the latest effectiveFrom date. So for the above sample data for employeeId 1000 the first row would be the requried result.
SELECT
`es`.`employeeSalaryId`,
`es`.`employeeId`,
`es`.`totalSalary`,
`es`.`currency`,
MAX(DATE(`es`.`effectiveFrom`)) AS `MAXeffectiveFrom`
FROM
`Employee_Salary` `es`
WHERE
`es`.`employeeId` = 1000;
I am getting the result below which is not correct,
employeeSalaryId employeeId totalSalary currency MAXeffectiveFrom
4 1000 19500.00 USD 2021-01-01
The date is correct but the totalSalary & employeeSalaryId values shown are for date 2020-09-23.
Desired Result is,
employeeSalaryId employeeId title value currency effectiveFrom
10 1000 Salary 22750.00 USD 2021-01-01