我正在尝试获取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
当我只联接两个表时,它的运行正常,例如:
select * from table1
union all
select * from table2
这个查询的结果不应该超过97个字段;两个表的UNION只有97个。那么为什么我使用三个表时会出现“字段太多”的错误?
编辑:如下面RichardTheKiwi所述,Access正在对UNION链中每个SELECT查询的字段计数求和,这意味着我的3个表超过了255个字段的最大限制。因此,我需要像这样编写查询:
select * from table1
union all
select * from
(select * from table2
union all
select * from table3)
这工作很好。