
In a many-to-one kind of relationship, one row of the first table can be related to one single row of the second table, and one row of the second table can be related to multiple rows of the first table. In a relational database this can be implemented with the second table having a first_table_id column that says to which row of the first table that row is related. In a one-to-many kind of relationship, one row of the first table can be related to multiple rows of the second table. When you have tables that are related to each other, their relationships could be one of various types. Let's talk a moment about the relationships you can have between tables and why you might want to join three tables together. To do that you add a second INNER JOIN statement and a second ON statement to indicate the third table and the second relationship. ON table2.id = table3.id Generic INNER JOIN statement between three tables It is possible to use multiple join statements together to join more than one table at the same time. In this case the two tables are joined using the relationship table1.id = table2.id. How the two tables should be joined is written in the ON statement. FROM statement indicates which is the first table, then the second table name is written just after the INNER JOIN keywords. ON table1.id = table2.id Generic INNER JOIN statement between two tables Join is a statement that lets you put together two tables, matching rows that are related to each other, and keeping only the rows that can be matched, not keeping unpaired rows. I have already written about SQL joins here and here, but let's take a moment to review how a join works first, and particularly the syntax specific to MySQL.

When you're working with your database, you might need to put together data from a few different tables.
