mysql - Replace the id's with name using single query -


select team_with.participant1,team_with.participant2,team_with.participant3   event,team_with   team_with.for_event_no=event.event_no ,   event.event_no=4 ,   team_with.participant1=9 or   team_with.participant2=9 or   team_with.participant3=9; 

i have written particular query, , obtained required id's in row. not able modify query such that, in place of these id's, names connected id's displayed.

the student_detatil table consists of pk(sam_id) , attribute name.

ids displayed present query fks connected student_detail.sam_id..

it seems bad design multiply columns storing different participants. consider creating separate row each participant , storing them in table. joining logic easier.

also, please use explicit join syntax - makes query clearer , easier understand separating join logic conditions data retrieval.

remember operator and has precedence on or, event.event_no = 4 not apply each participant condition. believe mistake, 1 judge.

as query itself, apply or conditions join, or join student_detail table thrice.

select      s1.name,     s2.name,     s3.name      event e      inner join team_with t on t.for_event_no = e.event_no     left join student_detail s1 on s1.sam_id = t.participant1     left join student_detail s2 on s2.sam_id = t.participant2     left join student_detail s3 on s3.sam_id = t.participant3     e.event_no = 4     , ( t.participant1=9 or t.participant2=9 or t.participant3=9 ); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -