我有几个需要连接的表。这些表是:
球员
- 名
- 姓
- 性别
- location_id
- (其他不相关的列)
和
score_entry
- 分数
- 约会时间
- player_id
- (其他不相关的列)
我需要根据player_id
并且只想选择players.location_id
最大的记录来加入他们。所以是这样的:
SELECT
players.first_name,
players.last_name,
players.gender,
score_entries.score,
score_entries.datetime as jump_date
players.location_id,
FROM score_entries
LEFT JOIN players
ON score_entries.player_id = players.id
WHERE gender="m"
AND location_id="***(ONLY THE HIGHEST LOCATION_ID VALUE IN THE TABLE)***"