Full Version: Union Query Written Incorrectly?
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
vic_finance
Hello!
I'm obviously doing something wrong with my union query b/c I'm getting more records than I should.
Not sure how I can write a Union query where I can get the Facility ID and the month where they are equal in each table. This is what I wrote, which gave me duplicate facility numbers.
Select `Month Year Formatted`, `Facility ID` FROM 1a_Construction_Month_Format WHERE `TotalNBV`<>"0" UNION Select `Booking Date`, `Facility ID` FROM 1b_Construction_BookingDt_Format
WHERE `TotalNBV`<>"0"
ORDER BY `Facility ID`;
I basically only want the facility Id and the date where the Month Year Formatted and the Booking date are equal.
Instead, I'm getting the date and facility id where TotalNBV<>0.
Thanks.
fkegley
A query that fetches the FacilityID and Month Year Formatted from the table. Another that fetches the FacilityID and Booking date.

A third that uses those two as its tables. Join on the FacilityID in each and Month Year Formatted and Booking date fields.
vic_finance
Again, thanks! I think you're usually the one who answers most of my questions.
sad.gif
fkegley
You're welcome. I am glad I could help this time and all the other times, too.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.