I have this SQL:
SELECT Ph.Account, Ph.Ct FROM Ph
UNION SELECT Rx.Account, Rx.Ct FROM Rx;
Which works fine, but the Ph.Ct and Rx.Ct fields may not always be the same. So I wanted to display both of them, but the query is only showing 1 “Ct” field and not both.
How can I have it show both?
Here’s ph:
12685 3
29568 1
38771 2
Here’s rx:
10657 1
12685 2
68781 2
79874 1
What’s what I want to come out from the query:
Account ph.ct rx.ct
10657 1
12685 3 2
29568 1
38771 2
68781 2
79874 1
A UNION gets the correct data set (about 800 results), but not the right fields. Any JOINs I’ve tried do not give the right data set (only about 300 results).
What you need is a full outer join. For each value of
Accountappearing in either table, this will give the corresponding values ofCtfor each table if the given value ofAccountappears and null otherwise.Edit: Since Access apparently doesn’t support full outer joins (for some god awful reason), you can achieve the same effect with the union of a left join with a right join:
which is also equivalent to (the probably faster):