Search code examples
ms-accessms-access-2007

How to add where clause in access join query


I have query like this.

SELECT account.AccountNumber, account.Name, Sum(agro.price*agro.qty) AS Expr1
FROM account,data  INNER JOIN (agro INNER JOIN data ON agro.BillNo = data.BillNo) ON    
account.AccountNumber = data.acno
GROUP BY account.AccountNumber, account.Name;

I want to add where db='true' this columns is of 'data' table then how can i do pls help me?


Solution

  • Try this:

    SELECT account.AccountNumber, account.NAME, Sum(agro.price * agro.qty) AS Expr1
    FROM ((account
    INNER JOIN data ON account.AccountNumber = data.acno)
    INNER JOIN agro ON agro.BillNo = data.BillNo)
    WHERE data.db='true'
    GROUP BY account.AccountNumber, account.NAME;
    

    You had some confusion in your JOINs, but i think this is what you were aiming for