user3361761
user3361761

Reputation: 259

Multiple natural joins in a SQL query?

I have three tables: Orders, Items and Items_Orders. There is a many-to-many relationship between Items and Orders implemented by the Items_Orders table. I am trying to perform a query which does a natural join on all three tables (to see which items are in each order).

Here is the SQL code I currently have:

SELECT * FROM Orders 
WHERE customer= 'username' NATURAL JOIN Items_Orders NATURAL JOIN Items

However, I am getting a very non-descript error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NATURAL JOIN Items_Orders NATURAL JOIN Items'

Any ideas as to what I am doing wrong here?

Upvotes: 0

Views: 13730

Answers (1)

mkubacki
mkubacki

Reputation: 585

Shouldn't it be something like this?

SELECT * FROM Orders NATURAL JOIN Items_Orders NATURAL JOIN Items
WHERE customer= 'username' 

Upvotes: 3

Related Questions