Chelmet
Chelmet

Reputation: 65

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 to this to get a 1:1 output?

Upvotes: 2

Views: 97

Answers (1)

Dave
Dave

Reputation: 11889

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.

Upvotes: 1

Related Questions