0

我需要选择n 个表中的所有行,其中n > 15 in ms 访问数据集。单个查询导致错误“定义的字段过多”。我的猜测是它超过了 255 个字段的限制。

SELECT * FROM ((((((((((((((((Forms 
LEFT JOIN Layouts ON Layouts.Name = Forms.Name) 
LEFT JOIN Layout ON Layout.Name = Forms.Name) 
LEFT JOIN Form ON Form.Name = Forms.Name) 
LEFT JOIN Sections ON Sections.ID] = Form.ID) 
LEFT JOIN Checks ON Checks.ID = Form.ID) 
LEFT JOIN Dates ON Dates.ID = Form.ID) 
LEFT JOIN Combos ON Combos.ID = Form.ID) 
LEFT JOIN Labels ON Labels.ID = Form.ID) 
LEFT JOIN Flash ON Flash.ID = Form.ID) 
LEFT JOIN Links ON Links.ID = Form.ID) 
LEFT JOIN Groups ON Groups.ID = Form.ID) 
LEFT JOIN Lists ON Lists.ID = Form.ID) 
LEFT JOIN Pictures ON Pictures.ID = Form.ID) 
LEFT JOIN Grids ON Grids.ID = Form.ID) 
LEFT JOIN Shapes ON Shapes.ID = Form.ID) 
LEFT JOIN Texts ON Texts.ID = Form.ID) 
WHERE Forms.Name = 'History'

我从一些 SO 用户那里读到,这种访问大量列/字段的方法是不合适或不好的做法。在许多表都相关的情况下,获取大量字段的正确方法或思维方式是什么?

4

1 回答 1

0

您的查询中的问题是select *,而不是联接。如果Form.Id真的是您想要加入的领域,那么这些联接可能会很好。

相反,列出选择中的列:

SELECT col1, col2, col3 . . .
FROM ((((((((((((((((Forms 
LEFT JOIN Layouts ON Layouts.Name = Forms.Name) 
LEFT JOIN Layout ON Layout.Name = Forms.Name) 
LEFT JOIN Form ON Form.Name = Forms.Name) 
LEFT JOIN Sections ON Sections.ID] = Form.ID) 
LEFT JOIN Checks ON Checks.ID = Form.ID) 
LEFT JOIN Dates ON Dates.ID = Form.ID) 
LEFT JOIN Combos ON Combos.ID = Form.ID) 
LEFT JOIN Labels ON Labels.ID = Form.ID) 
LEFT JOIN Flash ON Flash.ID = Form.ID) 
LEFT JOIN Links ON Links.ID = Form.ID) 
LEFT JOIN Groups ON Groups.ID = Form.ID) 
LEFT JOIN Lists ON Lists.ID = Form.ID) 
LEFT JOIN Pictures ON Pictures.ID = Form.ID) 
LEFT JOIN Grids ON Grids.ID = Form.ID) 
LEFT JOIN Shapes ON Shapes.ID = Form.ID) 
LEFT JOIN Texts ON Texts.ID = Form.ID) 
WHERE Forms.Name = 'History'
于 2013-06-03T15:38:50.053 回答