thinkphp三表查询问题,join查询
三个表,r_hospital表r_department表r_doctor表idid,hospital_idid,depart_id,hospital_id三个表所属关系如...
三个表,r_hospital表 r_department表 r_doctor表
id id ,hospital_id id , depart_id ,hospital_id
三个表所属关系如上,
两个表关联:我会了,
$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select();
求三个表关联语句?
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id left join doctor on doctor.id = xx.id')->where($condition)->select(); 这语句不对,不知道哪有问题 展开
id id ,hospital_id id , depart_id ,hospital_id
三个表所属关系如上,
两个表关联:我会了,
$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select();
求三个表关联语句?
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id left join doctor on doctor.id = xx.id')->where($condition)->select(); 这语句不对,不知道哪有问题 展开
1个回答
展开全部
可以写两个join
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id ')->join(' doctor on doctor.id = xx.id')->where($condition)->select();
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id ')->join(' doctor on doctor.id = xx.id')->where($condition)->select();
更多追问追答
追问
写了两个join还是不行,->join('left join r_department r on r_doctor.depart_id=r.id')->join('left join r_hospital h on r_doctor.hospital_id=h.id')
追答
->join('left join r_department r on r_doctor.depart_id=r.id')->join('left join r_hospital h on r_doctor.hospital_id=h.id')
join('left join r_department r on r_doctor.depart_id=r.id')这里面就不用写left join了吧
还有就是你吧你的sql语句打印出来然后放到数据库里面看看可不可以执行
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询