Using MS Access with a SQL Server back end, I have one table basically storing groupings of the Parameter field from another table.
For example, I have the parameters stored in TBL_Parameter: (Just a very small subset of the data)
Parameter Iron (Fe) Iron (Fe)-Dissolved Iron (Fe)-Total
The table, TBL_ParentParameter looks like this:
Parent Child Iron (Fe) Iron (Fe)-Dissolved Iron (Fe) Iron (Fe)-Total
Then I want to create a query to combine all parameters not contained as a child in TBL_ParentParameter with all the ones that are contained in TBL_ParentParameter, so I made the following union query:
SELECT Parameter, Parameter AS Child
FROM TBL_Parameter
WHERE Parameter NOT IN(SELECT Child FROM TBL_ParentParameter)
UNION
SELECT Parent AS Parameter, Child
FROM TBL_ParentParameter
This has the expected results of:
Parent Child Iron (Fe) Iron (Fe) Iron (Fe) Iron (Fe)-Dissolved Iron (Fe) Iron (Fe)-Total
But instead gives:
Parent Child Iron (Fe) Iron (Fe) Iron (Fe)-Dissolved Iron (Fe)-Dissolved Iron (Fe)-Total Iron (Fe)-Total
Now each query within the union query works perfectly fine individually, but when unioned, they don’t work properly. I have tried this exact same query as a passthrough query directly to the SQL server, which works just fine, but if I base other queries on this query, I find that it can take a few times longer to run. So does anyone have any idea what the issue is here? Is this some sort of MS Access bug? Or am I looking at this wrong?
SOLVED: It appears that this is a bug with MS Access, and reversing the order of the two union subqueries fixed the issue.
It appears that this is a bug with MS Access, and reversing the order of the two union subqueries fixed the issue.