2013-10-18 62 views
0

我得到一個語法錯誤在FROM子句中的對話框,當我嘗試運行MS-Access 2010中的下列查詢連接對話框訪問高亮顯示(在FROM聯繫人地址後面)語法錯誤FROM子句中一個MS Access

我知道我需要在Access中使用多個嵌套聯接的括號,但是有人可以解釋這是如何工作的概念,除了顯示如何修復問題是?

相關方面基本表模式的s應該從SQL SELECT語句中清除。

+2

一般情況下,你應該有一個表的別名爲每個子(選擇...)作爲X左連接(選擇...)AS Y' – Kaf

+0

您的括號有點扭曲,它應該看起來像:from(table或query)left join(table或qry)on col = col。在contact_addresses和左連接之間設置的括號不應該在那裏(表別名註釋aboe也應該注意) – Twelfth

回答

1

我認爲這應該工作,但我缺乏測試的權限。一般語法堅持

從表 左連接(聲明)別名 上table.col = alias.col 左加入...

改變你的語句是:

FROM Contact_addresses 

    LEFT JOIN 
     (SELECT 
      Owner_Operator.CONTACT_ID, 
      Owner_Operator.FIRM_NAME 
      FROM Owner_Operator) Owner_Operator 
     ON Contact_addresses.ContactID=Owner_Operator.CONTACT_ID 

    LEFT JOIN 
     (SELECT 
      Official_Correspondent.CONTACT_ID, 
      Official_Correspondent.FIRST_NAME, 
      Official_Correspondent.LAST_NAME, 
      Official_Correspondent.SUBACCOUNT_COMPANY_NAME, 
      Official_Correspondent.PHONE_NUMBER 
      FROM Official_Correspondent) Official_Correspondent 
     ON Contact_addresses.ContactID=Official_Correspondent.CONTACT_ID 
    ; 

我添加了表別名以匹配您在聯接中調用它的內容,並刪除了違規的一組括號。

+0

+1試圖幫助。謝謝。你的改變,現在正在拋出「語法錯誤(缺少操作符)在查詢表達式'Contact_addresses.ContactID = Owner_Operator.CONTACT_ID ...(到查詢結尾)'「。還有什麼想法? – CodeMed

+0

我修復了這個問題。查看我剛剛發佈的與您的答案。再次感謝你。 – CodeMed

0

的問題是在開括號((他們需要第一FROM後立即的位置下面是什麼在起作用:。

SELECT Contact_addresses.AddressID, Contact_addresses.ContactID, Contact_addresses.Address1, Contact_addresses.Address2, Contact_addresses.City, Contact_addresses.State, Contact_addresses.Zip, Owner_Operator.FIRM_NAME, Official_Correspondent.FIRST_NAME, Official_Correspondent.LAST_NAME, Official_Correspondent.SUBACCOUNT_COMPANY_NAME, Official_Correspondent.PHONE_NUMBER 
FROM ((Contact_addresses 

     LEFT JOIN 
      (SELECT 
       Owner_Operator.CONTACT_ID, 
       Owner_Operator.FIRM_NAME 
       FROM Owner_Operator) AS Owner_Operator 
      ON Contact_addresses.ContactID=Owner_Operator.CONTACT_ID 
) 
     LEFT JOIN 
      (SELECT 
       Official_Correspondent.CONTACT_ID, 
       Official_Correspondent.FIRST_NAME, 
       Official_Correspondent.LAST_NAME, 
       Official_Correspondent.SUBACCOUNT_COMPANY_NAME, 
       Official_Correspondent.PHONE_NUMBER 
       FROM Official_Correspondent) AS Official_Correspondent 
      ON Contact_addresses.ContactID=Official_Correspondent.CONTACT_ID 
)   
; 
+0

很好的解決方案... Access是一個棘手的SQL實現,它依賴於非常獨特的SQL語法。 – Twelfth

相關問題