Jack Smother
Jack Smother

Reputation: 207

How to join three tables in MySQL

select a.CHAR_DATE, a.CHAR_DESTINATION, a.AC_NUMBER, c.MOD_NAME, c.MOD_CHG_MILE
from CHARTER a JOIN AIRCRAFT b
on a.AC_NUMBER = b.AC_NUMBER
AND MODEL c JOIN AIRCRAFT
on c.MOD_CODE = a.MODE_CODE

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'c JOIN AIRCRAFT on c.MOD_CODE = a.MODE_CODE' at line 4

I'm getting a syntax error on joining three tables where A - B - C (A has a common column with B, and B has a common column with C). What have I done wrong?

Upvotes: 0

Views: 420

Answers (1)

sashkello
sashkello

Reputation: 17871

This is the right way:

CHARTER a JOIN AIRCRAFT b on a.AC_NUMBER = b.AC_NUMBER
JOIN MODEL c on c.MOD_CODE = a.MODE_CODE

That AND is not needed - you just join another table with two previous joined together.

Upvotes: 1

Related Questions