Join three table in JDBC

14,356

Try using parenthesis like this:

query = "SELECT * "+
        "FROM (Product " +
        "INNER JOIN Orders ON (Product.ItemID=Orders.ItemID)) " +
        "LEFT OUTER JOIN SupplierProduct ON (Orders.ItemID=SupplierProduct.ItemID) "+
        "WHERE Product.Reciever = 'Fred' " +
        "ORDER BY Product.ItemName";  
Share:
14,356
Themonkey180
Author by

Themonkey180

Updated on June 04, 2022

Comments

  • Themonkey180
    Themonkey180 almost 2 years

    I have this code and keep getting a syntax error.

    query = "SELECT * "+
    "FROM Product " +
    "INNER JOIN Orders ON (Product.ItemID=Orders.ItemID) " +
    "LEFT OUTER JOIN SupplierProduct ON (Orders.ItemID=SupplierProduct.ItemID) "+
    "WHERE Product.Receiver = 'Fred' " +
    "ORDER BY Product.ItemName";    
    
    DefaultTableModel data = table.getQuery(query);
    

    I also have tried an INNER JOIN in place of the LEFT OUTER JOIN. The error I keep getting what ever I try is.

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing     operator) in query expression '(Product.ItemID=Orders.ItemID) LEFT OUTER JOIN  SupplierProduct ON (Orders.ItemID=SupplierProduct.ItemID'.
    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)
    

    What am I missing here or how can I JOIN three table.

  • Themonkey180
    Themonkey180 over 10 years
    Thanks you this did work for me. I did not know that brackets was need.
  • Themonkey180
    Themonkey180 over 10 years
    Thank you for the details. Help me under stand it.