thinkphp关联模型 多对多查询应该怎么写?

2025-03-04 14:44:05
推荐回答(2个)
回答1:

可以直接写sql,不是一定要用thinkphp的组合语法啊。

M()->Query("select * from tableA a left join tableB b on a.id=b.id left join tableC c on b.id=c.id where c.id=1");// 类似这样

回答2:

直接join
教师表 teacher
学生表 student
课程表 class
选课表 class_map

select * from teacher inner join class on class.teacher_id=teacher.id
left join class_map on class_map.class_id=class.id

left join student on student.id=map.student_id

where teacher.id=xxxxx