我正在尝试获得 3 个表的 UNION,每个表都有 97 个字段。我尝试了以下方法:
select * from table1
union all
select * from table2
union all
select * from table3
这给了我一条错误消息:
Too many fields defined.
我还尝试从第一个表中显式选择所有字段名称(为简洁起见添加了省略号):
select [field1],[field2]...[field97] from table1
union all
select * from table2
union all
select * from table3
当我只 UNION 两个这样的表时,它工作正常:
select * from table1
union all
select * from table2
作为这个查询的结果,我不应该得到超过 97 个字段;两桌 UNION 只有 97。那为什么我要Too many fields
3 桌呢?
编辑:正如 RichardTheKiwi 在下面指出的,Access 正在总结 UNION 链中每个 SELECT 查询的字段计数,这意味着我的 3 个表超过了 255 个字段的最大值。因此,我需要像这样编写查询:
select * from table1
union all
select * from
(select * from table2
union all
select * from table3)
效果很好。