Is it possible and how in one query to refer to three tables at once?
If not difficult, with an example.
SELECT a.name, b.name, c.name FROM table1 as a, table2 as b, table3 as c ON, but what next?
Sure you may. Using the SELECT ... FROM ... construct. Field names must be comma-separated and better with an abbreviation ('.. AS ..'). Example: 3 tables (table1, table2, table3). It is necessary to take the fields of the corresponding row1, row2, row3.
SELECT a.row1,b.row2,c.row3 FROM table1 as a, table2 as b, table3 as c` JOIN: wikipedia , there are examples.
It depends on what result the query should produce for these tables, besides join I recommend reading about UNION
SELECT a.name, b.name, c.name FROM table1 as a full join table2 as b on a.row=b.row full join table3 as c ON a.row=c.row This is how three tables are combined without losing data, if there is no match in one of the tables.
If it is necessary to save values from only one table, the left join and the right join , depending on the cost of the saved table from the join .
Source: https://ru.stackoverflow.com/questions/65811/
All Articles