"SQL" Association query + table self-correlating query

Source: Internet
Author: User

Table:

Reseller Dealer Field UID Parent_uid name

Contact Contacts Field UID dealer_id contact_main

Demand:

Want to inquire about the reseller's information, and the main contact information of this reseller, and the reseller's parent reseller's name

Case

There may be parent_id that are null

SQL statements:

    SELECT        dea.uid uid,        dea.enabled_flag enabledflag,        dea.delete_flag Deleteflag,        dea.tenement_id Tenementid,        dea.parent_id parentid,        pd.name parentname,        dea.name name,        dea.type Type,        dea.bar_code barCode,        dea.outer_code outercode,        dea.outer_id Outerid,        Dea.mne_code  Mnecode,        dea.address address,        dea.address_xy addressxy,        Dea.business_area Businessarea,        dea.business_area_xy businessareaxy,        con.name  contactName,        con.mobile mobile    from        Dealer as DEA    Left JOIN  * from the contact where tenement_id = ' 9f63f84f-52c6-4c8e-b3c3-66b9f1f283ba ' and main_contact = 1) con on Dea.uid = con.dealer_id left    JOIN  = dea.parent_id

"SQL" Association query + table self-correlating query

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.