At first we used the most days, and if we didn't have a left join, we'd be like
The code is as follows |
Copy Code |
Select C.nom, E.nom From consultant C, affaire A, besoin B, Salarie SA, site s, entreprise E where c.consultant_id=a.consultant_id and a.besoin_id=b.besoin_id and b.salarie_id=sa.salarie_id and ssa.site_id=s.site_id and s.entreprise_id=e.entreprise_id |
It's not as good as green in the left join.
Left Join
The code is as follows |
Copy Code |
SELECT a.ID, A.number, A.price, A.order_time, b.user_id, B.startime, B.stoptime, C.channel_pay, D.company From D Table D Left JOIN A table A on a.company_id = D.uid Left JOIN b Table B on b.company_id = D.uid Left JOIN C Table C on c.company_id = D.uid Conditional addition Line: WHERE ..... Sort (for example, the ID of table A is from large to small rows): ORDER BY a.ID DESC |
The inner join method is also available for multiple table joint search
The code is as follows |
Copy Code |
Select C.nom, e.nom from consultant C INNER join affaire a on c.consultant_id=a.consultant_id inner Join besoin B on a.besoin_id=b.besoin_id inner join Salarie SA on b.salarie_id=sa.salarie_id inner Join site S on ssa.site_id=s.site_id inner join entreprise E on s.entreprise_id=e.entreprise_id |
Attention
Multi-Table union query there are a lot of ways right join, INNER join, full join is not introduced here.