I have Statement A and Statement B.
Statement A returns 5 records and statement B returns 1 record.
Statement A
SELECT DISTINCT
Outlet.cCode,
Employee.cEmployeeNumber,
FROM Outlet
INNER JOIN Employee ON EmployeeOutlet.iEmployee = Employee.iID
WHERE cCOde = 123
Statement B
Select OutletCode, RSMcode, ASMcode, FMcode from Employee_Hierarchy
Where OutletCode = 123
Now just 3 of the records from Statement A must be returned with the Employee.cEmployeeNumber is either equal to RSMcode, ASMcode or FMcode……
Now if I add the following JOIN in it will just return 1 records, how do I cater for the other 2 that are still needed?
SELECT DISTINCT
Outlet.cCode,
Employee.cEmployeeNumber,
FROM Outlet
INNER JOIN Employee ON EmployeeOutlet.iEmployee = Employee.iID
INNER JOIN Employee_Hierarchy as EH ON EH.RSMcode = Employee.cEmployeeNumber and EH.OutletCode = Outlet.cCode
WHERE Outlet.cCode = 123
When I add a JOIN for each RSMcode and ASMcode and FMcode it returns nothing…..
How’s this?