0

I am using the OleDbDataReader to access an Access Database with 3 tables. The database contains the main "Membership" table with a column ID, and a "Payment" and "Boat" table both using the ID as a foreign key called PID and BID respectively.

The following SQL query runs correctly and returns the correct values from the Membership and Payment tables.

SELECT * 
  FROM Membership 
INNER JOIN Payment ON Membership.ID = Payment.PID;

Whereas the following SQL query generates an error when trying to access all 3 tables:

SELECT * 
  FROM Membership 
INNER JOIN Payment ON Membership.ID = Payment.PID 
INNER JOIN Boat ON Membership.ID = Boat.BID;

Error: Additional information: Syntax error (missing operator) in query expression 'Membership.ID = Payment.PID INNER JOIN Boat ON Membership.ID = Boat.BI'.

Due to the error I am starting to wonder whether the OleDbDataReader is capable of executing two INNER JOINs as it asks for a missing operator, however I have tried all the usual ones and cannot seem to get the query to run correctly. Any help would be greatly appreciated :)

1 Answer 1

2

MS Access requires additional parentheses for multiple joins:

SELECT *
FROM (Membership INNER JOIN
      Payment
      ON Membership.ID = Payment.PID
     ) INNER JOIN
     Boat
     ON Membership.ID = Boat.BID;

You should also explicitly list the columns that you want to avoid duplicate column names.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked thanks, the only reason I don't list the columns is because I have around 20 columns and it's a small enough amount to avoid duplicates while also a large amount to list out. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.