Questions about two query statements for a single mysql table

Source: Internet
Author: User
Regarding the two query statements of a single mysql table, in tab1, FID is the parent column ID. for example, if fid of Yichang Wuhan is 1, it is now known that AID in tab1 is 3, how can I query table Tab1 to obtain the tongji field in Hubei province? how can I check whether the tongji field in the parent column of AID is 3 ., SQLcodeSELECTt1.t about two query statements for a single mysql table

,,



In tab1, FID is the parent column ID. for example, if the fid of Yichang Wuhan is 1, it is now known that AID in tab1 is 3, how can I query table Tab1 to obtain the tongji field in Hubei province? how can I check whether the tongji field in the parent column of AID is 3.


------ Solution --------------------
SQL code
SELECT t1.tongji FROM tab1 t1 left join tab1 t2 ON t1.AID = t2.FAID WHERE t2.AID = 3
------ Solution --------------------
Query the tongji field in Hubei province:
SELECT tongji FROM Tab1 where area = 'hubei'

Query the tongji field in the parent column of aid 3.
SELECT tongji FROM Tab1 WHERE aid IN (SELECT faid FROM Tab1 WHERE aid = 3)

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.