select distinct games.*, teams.teamname as teamname
from games, teams
(((games.homeid=teams.id) or (games.visitorid=teams.id))
and ((games.homescore is not null) and (games.visitorscore is not null))
and (games.homescore<>999 and games.visitorscore<> 999))
order by games.homeid, games.visitorid
But when two teams in the same division ("A") play each other,
i get two results for the one game.
How can I get only the one entry for the game played between two
$sql= 'SELECT g.* FROM games g, teams t1, teams t2 WHERE
(g.homeid=t1.id AND g.visitorid=t2.id) AND (t1.division="A"
$sql = $sql.' AND (g.homescore IS NOT NULL AND g.visitorscore IS
NOT NULL) AND (g.homescore<>999 AND
g.visitorscore<>999) ORDER BY g.gamenum';
$query = mysql_query($sql);