How to filter SQL results in a has-many-through relation

后端 未结 13 1423
有刺的猬
有刺的猬 2020-11-21 05:17

Assuming I have the tables student, club, and student_club:

student {
    id
    name
}
club {
    id
    name
}
stude         


        
13条回答
  •  误落风尘
    2020-11-21 05:56

    SELECT s.*
    FROM student s
    INNER JOIN student_club sc_soccer ON s.id = sc_soccer.student_id
    INNER JOIN student_club sc_baseball ON s.id = sc_baseball.student_id
    WHERE 
     sc_baseball.club_id = 50 AND 
     sc_soccer.club_id = 30
    

提交回复
热议问题