Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

mysql多对多查询sql怎么写?

学生表、课程表、中间表,中间表存储学生所选的课程id和学生id,默认情况下查询显示所有学生基本信息 不能重复,然后通过筛课程来找学生有哪些,这些多对多查询怎么优化呢?求助 大佬们


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

假定学生表: students, 课程表: courses, 关系表:students_curses
如果没有筛选课程,默认显示全部学生信息,这个直接使用

selec * from students

如果筛选了课程,一般会直接使用:

select * from students left join students_couses on students.id = students_couses.students_id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...