Multi-Table Association call, a little complicated, the expert help thanks

Source: Internet
Author: User
Multi-Table Association call, a little complicated, the expert help thanks
Table Goods_area
Field goods_id City area
1 Beijing Grand Lookout Road


Table Business_circle
Field ID Name parent_id

This table is the parent class table for the regional shopping district
ID Name parent_id
1 Chaoyang 0
2 Changping 0
3 da Wang Road 1
Is ' big Hope Road ' is ' Chaoyang ' sub-class parent_id is the ID number of its parent class

The associated field for two tables is A.area=b.name


$sql = mysql_query ("SELECT * from Goods_area as a INNER joins Business_circle as B on A.area=b.name ORDER by a.goods_id ASC ");
while ($rs = Mysql_fetch_assoc ($sql)) {
echo $rs [' area ']. $rs [' parent_id ']. '
';
}




This makes it possible to invoke the value at the parent_id, but I want to invoke the name value of the condition parent_id = ID Table business_circle
And the result I want to turn out is a table $rs[' area ' in table b the value of the parent class name



Don't you know how to speak clearly? Master directly to the complete code, thank you

Share to:


------Solution--------------------
Select c.name,d.* from Business_circle as C, (SELECT * from Goods_area as a INNER joins Business_circle as B on A.area=b.nam e) as D where c.id=d.parent_id


That's what this is, C.name is the name you want.
  • 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.