Diana Laura
Diana Laura

Reputation: 77

How to make 2 different joins in one query (3 tables) on mysql

Let's say I have 3 tables and I want to join them like this:

table 1 join table 2 and table 2 join table 3

I'm trying the following code but I'm getting an error of syntax.

SELECT * from table1 join table2 and table2 join table3 on table1.id=table2.idA and table2.idB=table3.id

Upvotes: 0

Views: 2440

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269743

Study up a bit on SQL. The syntax looks like:

select *
from table1 join
     table2
     on table1.id = table2.idA join
     table3  
     on table2.idB = table3.id;

This is very basic JOIN syntax and should be covered in any tutorial, documentation, book, paper or whatever that you are using to learn SQL.

Upvotes: 2

Related Questions