我想从2个不同的表中获取数据

时间:2016-03-08 07:05:08

标签: mysql

如果我有

,我想明智地提取结果master.category
$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

2 个答案:

答案 0 :(得分:1)

执行JOIN之类的

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

答案 1 :(得分:0)

其查询通过主人的身份

提供所有信息
SELECT m.label, GROUP_CONCAT(Information) 
FROM Master m
JOIN Field f 
ON m.id = f.label_id
WHERE m.category = 'doctor'