2016-03-08 77 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' 
相關問題