2011-03-04 134 views
0

閱讀MS Access documentation以瞭解如何執行LEFT JOIN SQL操作。現在盯着我的查詢一個小時,卻沒有發現問題。MS Access LEFT JOIN SQL語法錯誤

SELECT gen_id_id 
    FROM ES_issue_table 
     LEFT JOIN __MOTHER_ISSUE_TABLE_6 
      ON ES_issue_table.issue_id = __MOTHER_ISSUE_TABLE_6.issue_id 

這給我的錯誤:

java.sql.SQLException: [Microsoft][Drivrutin f?r ODBC Microsoft Access] Syntaxfel i fr?geuttrycket 'ES_issue_table.issue_id = __MOTHER_ISSUE_TABLE_6.issue_id'. 
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source) 
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source) 
at daos.MdbDao.testQuery(MdbDao.java:146) 
at MdbDaoTest.testingQueries(MdbDaoTest.java:71) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
+0

有何幫助,當你說出這臺'gen_id_id'是從哪裏來的?例如:'ES_issue_table.gen_id_id' – Yoh 2011-03-04 10:33:06

+1

您應該使用MS ACCESS查詢接口或任何其他查詢工具來嘗試您的SELECT指令。是相同類型和大小的連接字段? – 2011-03-04 11:13:45

+0

奇數。這只是給你gyp的左連接嗎?即'SELECT * FROM ES_issue_table'和'SELECT * FROM __MOTHER_ISSUE_TABLE_6'都可以工作嗎?根據你所說的內容,無法看到你正在做的事情有什麼問題,所以也許它是你的列和數據類型。正如@Philippe所說,在Access中嘗試驗證查詢。 – 2011-03-04 11:17:42

回答

2

表名__MOTHER_ISSUE_TABLE_6不是一個有效的表相關名稱,因爲lea丁強調字符。嘗試一種替代 - 最好更短! - 表格相關名稱例如

SELECT * 
    FROM ES_issue_table AS E1 
     LEFT JOIN __MOTHER_ISSUE_TABLE_6 AS M6 
      ON E1.issue_id = M6.issue_id; 

如果你真的喜歡使用長表名,然後逃逸用方括號的即

SELECT * 
    FROM ES_issue_table 
     LEFT JOIN __MOTHER_ISSUE_TABLE_6 
      ON ES_issue_table.issue_id = [__MOTHER_ISSUE_TABLE_6].issue_id; 
+0

啊,謝謝一堆!將盡快嘗試。 – 2011-03-04 18:12:51

0

檢查中ES_issue_tableissue_id領域和__MOTHER_ISSUE_TABLE_6issue_id場是相同的數據類型(例如兩者或兩者文本