无法使用内部联接

时间:2016-09-05 13:01:10

标签: sql access-vba ms-access-2010

我访问我有两个表,我使用UNION ALL组合(这是按预期工作)。然后我想添加一个新列,根据colA中的值填充不同的信息。我创建了一个包含此信息的新表,我正在尝试使用内部联接来分配正确的信息。我收到以下错误消息:

查询表达式中的语法错误(缺少运算符)

SELECT `Sheet1$`.colA, `Sheet1$`.colB, '' AS colG,

table1 INNER JOIN tabl2 ON table1.label1 = table2.label2 AS colF

FROM (

SELECT `Sheet1$`.colA, `Sheet1$`.colB
FROM `Sheet1$` `Sheet1$`
UNION ALL
SELECT `Sheet2$`.colC, `Sheet2$`.colD
FROM `Sheet2$` `Sheet2$`
) t;

关于我如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

Your syntax is all wrong.. Try this :

SELECT t.colA, t.colB, '' AS colG, s.<YourDesiredColumn>
FROM (
    SELECT `Sheet1$`.colA, `Sheet1$`.colB
    FROM `Sheet1$` `Sheet1$`
    UNION ALL
    SELECT `Sheet2$`.colC, `Sheet2$`.colD
    FROM `Sheet2$` `Sheet2$`
    ) t
INNER JOIN table2 s ON t.colA = s.ColA

I didn't totally understand what do you need since the question was unclear. What is table1 and table2 ? How do they connect to the inner query? Anyway, adjust this.