mysql - SQL Many to Many - Very simple -


i have 3 tables

student: id int (pk), name varchar(255)

discipline: id int (pk), name varchar(255)

student_discipline: student_id int, discipline_id int

i know has many-to-many relationship, , more 1 joins necessary, i'm new sql, question is:

how can make query returns students 'john' starting name have 'math' discipline, student id , student name, example ?

any appretiated !

select * student tp join student_discipline tpt on tpt.sid = tp.sid join discipline t on tpt.did = t.did tp.name 'john%' , t.name = 'math' 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -