1
votes

Why am I not able to do this query in the following Database:W3 School Database (The tables are listed on the right side)?

SELECT Customers.CustomerName,
       OrderDetails.ProductID
FROM   Customers
       INNER JOIN Orders
         ON Customers.CustomerID = Orders.CustomerID
       INNER JOIN OrderDetails
         ON Orders.OrderID = OrderDetails.OrderID 

I am trying to see the productIDs of what customers have ordered. The query above should match customers with orders and then take those order ids and find the correct OrderDetails to output a table with CustomerName and ProductID.

I get the following error:

Syntax error (missing operator) in query expression 'Customers.CustomerID = Orders.CustomerID INNER JOIN OrderDetails ON Orders.OrderID = OrderDetails.OrderID.

Thanks in advance.

2
I would strongly advise against using W3Schools. They are not an accurate source for learning. Use platform documentation if possible. - Kermit
Works fine for me when I paste it into the box and click "run SQL" - Martin Smith
W3Schools is great, I learned a lot there! The query you posted works just fine, are you sure you it's the same as the query that gives an error? - Andomar
Which DBMS are you using? Postgres? Oracle? - a_horse_with_no_name
Maybe try a different browser. In any event the query is fine so there doesn't seem to be an on topic question here. - Martin Smith

2 Answers

1
votes

Is this an Access database? If so, you need parentheses when there's more than one JOIN:

SELECT Customers.CustomerName,
   OrderDetails.ProductID
FROM   (Customers
   INNER JOIN Orders
     ON Customers.CustomerID = Orders.CustomerID)
   INNER JOIN OrderDetails
     ON Orders.OrderID = OrderDetails.OrderID
0
votes

It works ok in Chrome, but fails in Firefox.

The reason is the w3c page runs SQL queries in your browser's WebSQL engine so as to not to overload the server. For the browsers which do not support WebSQL it resorts to an ASP WS which runs queries on a remote access database.

Thats why when in Firefox each join needs parentheses a là Access, but when in Chrome or any other websql-enabled browser you don't need them.