开发者

Left join, how to specify 1 result from the right?

This one is fairly specific, so I'm hoping for a quick fix.

I have a single result in my leaderboard table for each team. In my teams table, I have several results for each team (one result per game to enable team development history).

I want to show each team in the leaderboard once, and have teamID replaced by strName. Problem is, my left join is giving me one record for each team result; I just want a single record.

    SELECT * , a.strName AS teamName
FROM bb_leaderboards l
LEFT JOIN bb_teams a ON ( l.teamID = a.ID )
WHERE l.season =8
AND l.division =1
ORDER BY l.division DESC , points DESC , wins DESC , l.TDdiff DESC
LIMIT 0 , 30

What do I need to do t开发者_如何学Pythono this to get a 1:1 output?


You could do a SELECT DISTINCT instead, but you'll have to narrow down your select a bit. So:

SELECT DISTINCT l.*, a.strName AS teamName 
...

That should filter out the duplicates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜