"MYSQL" left joins on multiple table association queries (field resolution with duplicate names in the queried table)

Source: Internet
Author: User
Tags joins openid

When OpenID equals the Mendian field in the current Openid,order table and the contents of the ID field in Mendian, the order table is associated Mendian with the order form, and the data in the table order is taken out.

, (as M and as O are the store table as M, the order table as O)

SELECT * from ' order ' as O left join ' Mendian ' as M in M.id=o.mendian where O. ' OpenID ' = ' $openid ' ORDER by O.id DESC

The OrderID data in the order table is not available, the exclusion error found that two tables have common field OrderID, so use the following statement

Write the fields directly from each table you need to take out

SELECT ' order '. ' OrderID ', ' order '. ' Strshow ', ' order '. ' Create_time ', ' order '. ' Notes ', ' Mendian '. ' Corp_name ' from ' Orde R ' left JOIN ' Mendian ' on ' mendian '. id = ' order '. Mendian WHERE ' order '. ' OpenID ' = ' $openid ' ORDER by Order.id DESC

"MYSQL" left joins on multiple table association queries (field resolution with duplicate names in the queried table)

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.