SQL加入不正确

时间:2016-01-15 04:25:52

标签: sql ms-access join left-join

我试图从下图所示的数据库中选择值,以便我可以插入名为Desired Table的新表中。数据和调试位于Microsoft Access数据库中,我继续收到错误:

  

查询表达式中的语法错误。

此查询有什么问题?连接似乎是正确的,FROM子句也是如此。如果您需要更多信息,请与我们联系。不要担心INSERT条款。

查询:

SELECT vicdescriptions.vid, 
       vicdescriptions.make, 
       vicdescriptions.vic_year, 
       vicdescriptions.optiontable, 
       vacdescriptions.accessory, 
       vacvalues.value, 
       vicvalues.valuetype, 
       vicvalues.value 
FROM   vicdescriptions 
       JOIN vicvalues 
         ON ( vicdescriptions.vic_make = vicvalues.vic_make 
              AND vicdescriptions.vic_year = vicvalues.vic_year ); 

数据库结构:

DATABASE SCHEMA

要插入的表格:

enter image description here

5 个答案:

答案 0 :(得分:4)

Access不支持JOIN作为INNER JOIN的同义词。您必须始终指定JOIN的类型:

FROM   vicdescriptions 
       INNER JOIN vicvalues 
         ON ( vicdescriptions.vic_make = vicvalues.vic_make 
              AND vicdescriptions.vic_year = vicvalues.vic_year ) 

如果没有名为vicvalues的表格,在您将JOIN更改为INNER JOIN后,Access会向您显示不同的错误消息。

答案 1 :(得分:1)

我猜你应该只在加入两个时才使用括号  Ms-Access中的表加上它应该在第一个表名之前开始。尝试删除它。

.....
FROM   vicdescriptions 
       JOIN vicvalues 
         ON vicdescriptions.vic_make = vicvalues.vic_make 
             AND vicdescriptions.vic_year = vicvalues.vic_year

答案 2 :(得分:1)

SELECT vicdescriptions.vid, 
       vicdescriptions.make, 
       vicdescriptions.vic_year, 
       vicdescriptions.optiontable, 
       vacdescriptions.accessory, 
       vacvalues.value, 
       vicvalues.valuetype, 
       vicvalues.value 
FROM   vicdescriptions 
       JOIN vicvalues 
         ON ( vicdescriptions.vic_make = vicvalues.vic_make 
              AND vicdescriptions.vic_year = vicvalues.vic_year ); 

我想第5行,6个vacdescriptions,vacvalues>> vicdescriptions,vicvalues

答案 3 :(得分:1)

这是一个错误的vacdescriptions和vacvalues?

SELECT vicdescriptions.vid, 
       vicdescriptions.make, 
       vicdescriptions.vic_year, 
       vicdescriptions.optiontable, 
       **vicdescriptions.accessory, 
       vicvalues.value,** 
       vicvalues.valuetype, 
       vicvalues.value 
FROM   vicdescriptions 
       JOIN vicvalues 
         ON ( vicdescriptions.vic_make = vicvalues.vic_make 
              AND vicdescriptions.vic_year = vicvalues.vic_year ); 

答案 4 :(得分:0)

SELECT VicDescriptions.VID, 
       VicDescriptions.Make, 
       VicDescriptions.VIC_Year, 
       VicDescriptions.OptionTable, 
       VacDescriptions.accessory, 
       VacValues.value, 
       VacValues.valuetype, 
       VacValues.value --(No such table as VicValues available in the database, you only have VacValues)
FROM   VicDescriptions 
       JOIN VacValues --(No such table available in the database, you only have VacValues) 
         ON ( VicDescriptions.VIC_Make = VacValues.VIC_Make 
              AND VicDescriptions.VIC_Year = VacValues.VIC_Year )
       JOIN VacDescriptions
         ON ( VacDescriptions.Period = VacValues.Period
               AND VacDescriptions.VAC = VacValues.VAC);