简体   繁体   中英

Join expression not supported SQL

SELECT 
    Trs.itemID, Trs.imtName, Trs.sumQty,  Sum(whiQty) 
FROM 
    ((SELECT 
          trsitemID AS itemID, trsimtName AS imtName, 
          Sum(trsQty) As sumQty 
      FROM 
          tblTransactionSub AS T 
      WHERE 
          trstraID = 1231 
          AND trsActive = True  
      GROUP BY 
          trsitemID, trsimtName) AS Trs 
INNER JOIN 
   tblWarehouseItem AS WHI ON Trs.itemID = WHI.whiitemID)
RIGHT JOIN 
   WHI ON Trs.trswhiID = WHI.whiID 
WHERE 
    whiActive = True 
    AND whiCansel = False  
    AND whiwrhID = 19 
GROUP BY 
    Trs.itemID,Trs.imtName, Trs.sumQty 
HAVING 
    SUM(whiQty) < Trs.sumQty

If you please help me me out since I am new to SQL commands I can not easily find my mistake.

Thanks in advance

The error that occurred when I added the Right Join is:

Join expression not supported

In MS Access, you have to use parenthesises with multiple joins:

select ...
from 
    ((table1
    ... join table2 on ...)
    ... join table3 on ...)
    ... join tableN

/edit/

As OP question changes its syntax often, then my answer seems out of place :) Initially there were no parens there.

About RIGHT JOIN: You need to use table name (or entire subselect) after JOIN keyword, not skip it or use some other alias. Your query part

RIGHT JOIN 
    WHI ON Trs.trswhiID = WHI.whiID 

currently uses alias WHI, which is wrong in two ways: 1) it is not table name 2) it is already used. You need something like this:

RIGHT JOIN 
    tblWarehouseItem AS WHI2 ON Trs.trswhiID = WHI2.whiID 

It could be possible that MS Access restricts your kind of JOINs usage (like INNER join should not come after LEFT join); I have currently no possibility to check precise rules.

Your problem is that you have no table name after the RIGHT JOIN :

RIGHT JOIN 
   ON Trs.trswhiID = WHI.whiID 

Should be:

RIGHT JOIN YOURTABLENAMEHERE as alias
   ON Trs.trswhiID = WHI.whiID 

However, you have already defined Trs and Whi , so I have no idea what table you want there, or why. Perhaps you just want to change the INNER JOIN to a LEFT JOIN or RIGHT JOIN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM