Multi-table join call is a bit complicated. thanks for your help.

Source: Internet
Author: User
Multi-table join call is a bit complicated. thanks for the help of table goods_area.
Goods_id city area
1 Beijing Dawang Road


Table business_circle
Field id name parent_id

This table is the parent subclass table of the regional business area.
Id name parent_id
1 Chaoyang 0
2 Changping 0
3 Dawang Road 1
The child parent_id of 'dawang path' is the ID of its parent class.

The joined fields of the two tables are a. area = B. name.


$ SQL = mysql_query ("select * from goods_area as a inner join business_circle as B on a. area = B. name order by a. goods_id asc ");
While ($ rs = mysql_fetch_assoc ($ SQL )){
Echo $ rs ['region']. $ rs ['parent _ id'].'
';
}




In this way, you can call the value of parent_id, but I want to call the name value in the condition parent_id = id table business_circle.
The result I want to call is the value of the parent class name of Table B in table a $ rs ['region '].



Do you know how to make it clear? The master directly gave the complete code. thank you.


Reply to discussion (solution)

It may take two cycles to obtain the value of $ rs ['parent _ id'] and call it as a condition. how can I write the master code?

Select c. name, d. * from goods_area as c, (goods_area select * from goods_area as a inner join business_circle as B on. area = B. name) as d where c. id = d. parent_id

Select c. name, d. * from business_circle as c, (select * from goods_area as a inner join business_circle as B on. area = B. name) as d where c. id = d. parent_id


This should be the case. 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.