帮助多个内部联接查询

时间:2010-12-09 12:43:15

标签: sql ms-access

我有这个查询

SELECT t1.Trans_ID
FROM (SELECT * FROM Prune WHERE [Name]="I1")  AS t1 
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I2")  AS t2 ON (t1.Trans_ID = t2.Trans_ID)
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I3")  AS t3 ON (t1.Trans_ID = t3.Trans_ID)

我收到错误信息:“查询表达式中的语法错误(缺少运算符)

'(t1.Trans_ID = t2.Trans_ID)
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I3")  AS t3 ON (t1.Trans_ID = t3.Trans_ID)'

但是当我只使用1个内连接时,该查询工作正常

SELECT t1.Trans_ID
FROM (SELECT * FROM Prune WHERE [Name]="I1")  AS t1 
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I2")  AS t2 ON (t1.Trans_ID = t2.Trans_ID)
任何人都可以知道发生了什么?以及如何解决? 我正在使用ms access

2 个答案:

答案 0 :(得分:3)

MsAccess有时候很不舒服......

试试这个

SELECT t1.Trans_ID 
FROM ((SELECT * FROM Prune WHERE [Name]="I1")  AS t1  
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I2")  AS t2 ON (t1.Trans_ID = t2.Trans_ID))
INNER JOIN (SELECT * FROM Prune WHERE [Name]="I3")  AS t3 ON (t1.Trans_ID = t3.Trans_ID)

请注意FROM之后的其他左括号 以及t2.Trans_ID)之后的其他结束括号

答案 1 :(得分:2)

试试这个:

SELECT t1.Trans_ID
FROM Prune AS t1
INNER JOIN Prune AS t2 ON t1.Trans_ID = t2.Trans_ID
INNER JOIN Prune AS t3 ON t1.Trans_ID = t3.Trans_ID
WHERE t1.Name = "I1" AND t2.Name = "I2" AND t3.Name = "I3"