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 table & nbsp; goods_area field & nbsp; goods_id & nbsp; city & nbsp; area & nbsp; & nbsp; 1 & nbsp; & nbs multi-table Association call, a little complicated. thanks for your help.
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. thanks for sharing the following:
------ Solution --------------------
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.
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.