No just the same data types (I think, I'm not sure I have ever tried different datatypes??) and you must select the same number of columns
SELECT f1, f2, f4, f6 FROM Table1
Union
SELECT f01, f02, f04, f09 FROM Table2
Would be perfectly valid.
DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
Please use the star below the post to say thanks if we have helped !
↓↓ It's down here ↓↓
If there are not the same number of fields, use a filler - I prefer Null.
First SELECT determines field names and types unless data is mixed in a column then all in that column will be strings regardless of what the first SELECT contains. Multi-value field cannot be used in UNION.
SELECT f1, f2, f4, f6 AS Data FROM Table1
UNION
SELECT f01, f02, Null, f09 FROM Table2;
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Not really! Field count must be same for all subqueries, and fields in same position must be of same type (but e.g. text fields can be of different length) in all subqueries. The result table inherits field names from 1st subquery.
No, fields in same position do not have to be same type. They must be same type if you want to do some sort of operation, such as Sum or DateDiff.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
No, but the position of the fields should be of the same data type. IIRC, the output field names are those from the table in the first part of the Union.
EDIT - don't have to be of the same type, but if they are not, you can get unexpected results, especially if Nulls are involved.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.