select * from major_subject_discussion a join (select id from fa_user a join (select class from major_subject_classes a join (select subject_no from major_subject_chapter where subject_chapter_no = 'chapter_4') b on a.subject_no = b.subject_no) b on a.class = b.class) b on a.user_id = b.id where subject_chapter_no = 'chapter_4'
四表关联,使用join关键字,可以进行多表关联。
分解开:
第一个子查询
select subject_no from major_subject_chapter where subject_chapter_no = 'chapter_4'
第二个子查询
select class from major_subject_classes a join (select subject_no from major_subject_chapter where subject_chapter_no = 'chapter_4') b on a.subject_no = b.subject_no
通过join关键字,进行两表关联。
之后也是一样,来通过join达到子查询多表关联的效果。
本文详细解析了一个涉及四个表的复杂SQL关联查询语句,通过逐步分解,展示了如何使用JOIN关键字实现多表关联,为理解和编写类似SQL查询提供了清晰的指导。
3083

被折叠的 条评论
为什么被折叠?



