Why not just a simple join?
SELECT DISTINCT
N.id,
N.Alias,
N.Weight
FROM
Ninja N, Matchup M
WHERE
M.BlueCornerNinjaID = N.id
OR
M.RedCornerNinjaID = N.id
ORDER BY
N.Alias
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Did you check the query plan on the query I posted to see if it was using the indexes?
You could also try a UNION ALL of the sets for each corner, but there again I would expect that to be slower than the simple inner join.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Can u check how much time this query takes.
select
N.id,
N.Alias,
N.Weight
FROM
Ninja N left outer join Matchup Mb on Mb.BlueCornerNinjaID = N.id
left outer join Matchup Mr on Mr.RedCornerNinjaID = N.id
WHERE ifnull(Mb.BlueCornerNinjaID ,0)+ifnull(Mr.BlueCornerNinjaID ,0)>0
ORDER BY
N.Alias
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270