I'm having an issue with setting up a union query where I receive an error saying "Syntax error in query expression ''." I'm able to run all combinations of the union with just two of the queries, but when I add the third I run into this issue. I also have other queries in this database that have three parts that run with no issues. Below is the query I have right now.
For some additional detail, First, Second, and ThirdBranch all reference the same field from Branches and Overrides is a multiple-value field that I'm trying to get the values from and view all combinations of them and CWDepartment for Employees.
Code:
SELECT br2.Branch, cwd.CWDepartment
FROM ((Employees e
LEFT JOIN Branches br ON e.FirstBranch = br.BranchID)
LEFT JOIN Branches br2 ON br.Overrides.Value = br2.BranchID)
LEFT JOIN CWDepartments cwd ON e.CWDepartment = cwd.CWDepartmentID
WHERE br.OverrideBranch = True
UNION
SELECT br2.Branch, cwd.CWDepartment
FROM ((Employees e
LEFT JOIN Branches br ON e.SecondBranch = br.BranchID)
LEFT JOIN Branches br2 ON br.Overrides.Value = br2.BranchID)
LEFT JOIN CWDepartments cwd ON e.CWDepartment = cwd.CWDepartmentID
WHERE (br.OverrideBranch = True) AND (e.SecondBranch IS NOT NULL)
UNION
SELECT br2.Branch, cwd.CWDepartment
FROM ((Employees e
LEFT JOIN Branches br ON e.ThirdBranch = br.BranchID)
LEFT JOIN Branches br2 ON br.Overrides.Value = br2.BranchID)
LEFT JOIN CWDepartments cwd ON e.CWDepartment = cwd.CWDepartmentID
WHERE (br.OverrideBranch = True) AND (e.ThirdBranch IS NOT NULL)
For some additional detail, First, Second, and ThirdBranch all reference the same field from Branches and Overrides is a multiple-value field that I'm trying to get the values from and view all combinations of them and CWDepartment for Employees.