Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct not distinct...

Status
Not open for further replies.

Mrbaseball34

Programmer
Apr 17, 2002
24
US
I have this query...


select distinct games.*, teams.teamname as teamname
from games, teams
where
(((games.homeid=teams.id) or (games.visitorid=teams.id))
and (teams.division="A")
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 (&quot;A&quot;) 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 division opponents?

{Note: games with 999 as score are rainouts}
 
SELECT DISTINCTROW games.*, teams.teamname as teamname
FROM games, teams
WHERE
games.homeid = teams.id OR
games.visitorid = teams.id) AND
teams.division=&quot;A&quot; 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top