Left JOIN multi-table query statement in MySQL

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.