2016-03-08 51 views
1

我想获取引起master.category如果我有我想从2个不同的表中提取数据

$category ='doctor' 

明智假设那我怎么才能得到结果?我已经绘制了下面的表格和预期的结果,请帮助我。感谢

table name->Master 
------------------ 

id  label  category 

1  expertise  doctor 
2   fee   doctor 
3  appontment  doctor 
4  services  lawyer 
5  qualification student 





table name->Field 
------------------ 

id  label_id  Information 
1   1   desntist 
2   1   general_physician 
3   1   general_surgeons 
4   4   criminal_law 
5   5   civil_law 



expected result    
-------------------- 
expertise  

dentist 
general_physician 
general_surgeons 

回答

1

执行JOIN

select f.information as 'expertise' 
from field f 
join master m on m.id = f.label_id 
where m.category = 'doctor'; 
+0

谢谢你这么多的朋友。 – Divakarcool

0

其查询得到的所有信息通过大师的ID

SELECT m.label, GROUP_CONCAT(Information) 
FROM Master m 
JOIN Field f 
ON m.id = f.label_id 
WHERE m.category = 'doctor' 
相关问题