我有以下4个表:
Participant {id_participant, etc.}
Player {id_participant, name, phone, etc.}
Team {id_participant, name, phone, etc..}
Couple {id_participant, id_player1, id_player2}
Games {id_game, localization, etc.}
GamesParticipant { id_game, id_participant, type (p,t,c) }
在我的网站上,我需要进行许多涉及参与者的查询,而正常方式需要每个查询进行多次连接。我认为第一个解决方案是使用Player,Team,Couple的联合创建一个View,并对该视图进行查询,但阅读帖子MySQL view performance我不能使用union。
执行此操作的最佳方法是什么,是否可以使用存储过程?
感谢
答案 0 :(得分:0)
SELECT *
FROM Participant
LEFT JOIN Player
ON Player.id_participant = Participant.id_participant
LEFT JOIN Team
ON Team.id_participant = Participant.id_participant
LEFT JOIN Couple
ON Couple.id_participant = Participant.id_participant
LEFT JOIN GamesParticipant
ON GamesParticipant.id_participant = Participant.id_participant
LEFT JOIN Games
ON Games.id_game= GamesParticipant.id_game