我有大约20张桌子的玩家数据库。 我试图找出特定球员的首次亮相(首场比赛)。数据库有两个用于“外观”和“替换”的单独表格。最初我设法单独得到我的查询,也就是说我设法在一个查询中获取第一个外观的详细信息,并在另一个查询中获取替换的详细信息。我已经尝试了几个程序来将查询组合成一个,但是我尝试了eveytime,发生了一些错误。是的,我也做了很多谷歌搜索。 以下是单独的程序:
SELECT DATE( MatchDateTime ) , tplss_opponents.OpponentName, CONCAT(MatchGoals,"-", MatchGoalsOpponent), PlayerLastName
FROM tplss_matches
JOIN tplss_opponents ON tplss_matches.MatchOpponent = tplss_opponents.opponentID
JOIN tplss_appearances ON tplss_matches.MatchID = tplss_appearances.AppearanceMatchID
JOIN tplss_players ON tplss_appearances.AppearancePlayerID= tplss_players.PlayerID
WHERE `PlayerLastName` = "Leo Messi"
ORDER BY `MatchDateTime` ASC
LIMIT 1;
SELECT DATE( MatchDateTime ) , tplss_opponents.OpponentName, CONCAT(MatchGoals,"-", MatchGoalsOpponent), PlayerLastName
FROM tplss_matches
JOIN tplss_opponents ON tplss_matches.MatchOpponent = tplss_opponents.opponentID
JOIN tplss_substitutions ON tplss_matches.MatchID = tplss_substitutions.SubstitutionMatchID
JOIN tplss_players ON tplss_substitutions.SubstitutionPlayerIDIn= tplss_players.PlayerID
WHERE `PlayerLastName` = "Leo Messi"
ORDER BY `MatchDateTime` ASC
LIMIT 1;
我的目标是找到一名球员参加比赛的第一张记录,无论是先发球员还是板球替补球员,以较早者为准。这通常被称为“首次亮相”。
查询输出的示例:
DATE OpponentName结果PlayerLastName
2005-08-17匈牙利2-1 Lionel MESSI
感谢任何帮助或指导。
答案 0 :(得分:0)
您可以尝试使用'union all'和子查询:
SELECT * FROM (
-- Select from Debut --
UNION ALL
-- Select from substitution --
) AS tmp
ORDER BY MatchDateTime ASC
LIMIT 1