Union

kitty77

Registered User.
Local time
Today, 18:49
Joined
May 27, 2019
Messages
715
When you create a union query, do both queries have to be exactly the same fields?
I have one query that has 10 fields and the other 5. Can I create a union with those?
 
Yes but you have to call out the names of the fields for each. Cannot do select * ...Union Select *
 
Hi. I think there are two rules:

1. Both UNION sources must have the same number of columns, and
2. Each column must match data types.
 
When you create a union query, do both queries have to be exactly the same fields?
I have one query that has 10 fields and the other 5. Can I create a union with those?
The columns have to match, but you can fudge the situation by simply adding 5 more columns to the smaller query: "Null as fieldname, Null as fieldname", etc.
 
Three rules. As above plus:
3. The field names must be in the same order in each UNION section
 
This is one I use
SQL:
SELECT -1 As CityID, "<<ALL>>" As City FROM LtblCityLookup UNION SELECT LtblCityLookup.CityID, LtblCityLookup.City FROM LtblCityLookup
ORDER BY City;
 
The purpose of a union query is to combine 2 or more tables with the same exact table structure into a single structure. I agree with all of the friends. Therefore, logically, the number of columns and data types should also be the same. Finally, data duplicated in the union query is not shown in the result. If you want to show, Union All should be written instead of Union.
 

Users who are viewing this thread

Back
Top Bottom