Search code examples
sqlinner-joinouter-join

SQL error on multiple joins: "Encountered INNER. Was expecting one of "and"... "except"


SQL CODE BELOW - I am trying to join 4 tables. Error with the last inner join. Please advise.

enter image description here


Solution

  • Your last INNER JOIN is out of place. The order of elements in a SQL query is that joins come before the WHERE clause, and there is only one WHERE clause. End your query with this and the error should go away:

    INNER JOIN Cust c
        ON v.scnum = c.cnbr
    INNER JOIN cont d
        ON c.cnbr = d.cnbr
    WHERE
        current_date - c.cust_acct_crte_dt <= 730 AND
        d.role = 'PS';