Three table union queries we can use the following syntax
| The code is as follows |
Copy Code |
SELECT * from a LEFT join B to a.id=b.id left join C on b.id=c.id |
Example
Now it's time to list all the users and the departments and positions they belong to.
Tb_user Users
ID sname Id_pos
1 Li Good 2
2 Good inside 3
3 Small outside 1
Tb_pos position
ID scaption ID_DPT
1 Manager 0
2 Program 1
3 1
TB_DPT Department
ID scaption
1 Design Department
2 Operation and Maintenance department
Because you want to list each record in the tb_user, we need to use left JOIN to answer the query. And there are 3 tables to connect, so it should be written
| The code is as follows |
Copy Code |
SELECT u.sname p.scaption d.scaption from Tb_user as U Left join (Tb_pos as P-left join TB_DPT as D on p.id_dpt=d.id) on U . id_pos=p.id; |
Then after the run came out tb_user new table, the method is not very simple ah, here is also used in the left JOIN joint query.