a->b->c多个表之间相互传递的关系
$sql =
<<<EOF
select a.*,d.exam_name,d.subject_id,d.subject_name from ex_user_exam as a left join
(select b.id,b.name as exam_name,b.subject_id,c.name as subject_name from ex_exam as b left join ex_subject as c on b.subject_id = c.id) as d
on a.exam_id = d.id
EOF;
用外链接方法从底层往上查询
a->c<-b 两个表都和另外一个表有关系
$sql =
<<<EOF
(select a.id,a.info,a.subject_id,a.label_id,a.label_name,a.add_time,b.name as subject_name,a.type from ex_question as a left join ex_subject as b on a.subject_id = b.id)
union
(select a.id,a.info,a.subject_id,a.label_id,a.label_name,a.add_time,b.name as subject_name,5 as type from ex_material as a left join ex_subject as b on a.subject_id = b.id)
EOF;
union方法拼接记录数:要求是字段统一
时间: 2024-10-17 21:50:39