The query below fetches the wageTypeID based on the current active hiring info record and salary record.
SELECT wt.wageTypeID
FROM TimeSheet t
INNER JOIN Employee e ON e.employeeID = t.employeeID
INNER JOIN Salary s ON s.salaryID = t.salaryID
INNER JOIN Wage w ON w.wageID = s.wageID
INNER JOIN EmpHiringInfo ehf ON ehf.EmpHiringInfoID = s.EmpHiringInfoID
INNER JOIN WageType wt ON wt.wageTypeID = w.wageTypeID
WHERE ehf.employeeID = 300
AND ehf.isActive = 1
AND s.isActive = 1
The above query should return the value 15! I wonder where did i go wrong?
Here is the schema of the joined tables:
TimeSheet:
timeSheetID
employeeID - 300
salaryID
.
.
Salary:
salaryID
EmpHiringInfoID
wageID
isActive - true
.
.
WageType:
wageTypeID - 15
wageTypeTitle - Hourly
Wage:
wageID
wageTypeID - 15
wageAmount - $11
EmpHiringInfo:
EmpHiringInfoID
employeeID
isActive - true
.
.
The isActive in Salary is only and only True for one record. Same thing applied to EmpHiringInfo.