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

后端 未结 13 1457
有刺的猬
有刺的猬 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:52

    @erwin-brandstetter Please, benchmark this:

    SELECT s.stud_id, s.name
    FROM   student s, student_club x, student_club y
    WHERE  x.club_id = 30
    AND    s.stud_id = x.stud_id
    AND    y.club_id = 50
    AND    s.stud_id = y.stud_id;
    

    It's like number 6) by @sean , just cleaner, I guess.

提交回复
热议问题