Saturday 10 September 2016

Get Player Name and Coach Name from a single table in MYSQL ?


Table Name: playercoach
Player Coach Table
Here, the number in the column coach represents the sno of the coach.
Procedure 1:
SELECT player.sno,player.name,(SELECT coach.name FROM playercoach coach WHERE coach.sno=player.coach) AS coachname FROM playercoach player
Procedure 2:
SELECT player.sno,player.name,coach.name AS coachname FROM playercoach player JOIN playercoach coach ON coach.sno=player.coach
Output:
Procedure 1 would be better in the sense of performance.

No comments:

Post a Comment

Your comment is so valuable as it would help me in my growth of knowledge.