I have two tables (country & ducks) where the country table has every country in the world and the ducks table has a list of ducks with a country_id field to link to the
SELECT c.*, d.*
FROM country c
INNER JOIN ducks d
ON d.id = --- guessing the ducks Primary Key here
( SELECT dd.id --- and here
FROM ducks dd
WHERE c.id = dd.country_id
ORDER BY dd.rating DESC
LIMIT 1
)
An index on (country_id, rating, id)
for MyISAM table or (country_id, rating)
for InnoDB table, would help.
This query will show only one duck
per country, even with more than one having the same rating. If you want ducks with tied rating to appear, use @imm's GROUP BY
answer.