All pastes #910765 Raw Edit

Stuff

public text v1 · immutable
·published 2008-02-20 04:53 UTC
rendered paste body
try this
-----
DECLARE @teamID INT
SET @teamID=23

SELECT t1.name AS Team1, s1.score AS MyScore, t2.name as Team2, s2.score
FROM score s1
INNER JOIN t1 ON s1.tid_FK1 = t1.tid
INNER JOIN score s2 ON s1.date=s2.date AND s1.tid_FK1 = s2.tid_FK2 AND s1.tid_FK2 = s2.tid_FK1
INNER JOIN t2 ON s1.tid_FK2 = t2.tid
WHERE s1.tid_FK1 = @teamID

UNION

SELECT t1.name AS Team1, s1.score AS MyScore, t2.name as Team2, s2.score
FROM score s1
INNER JOIN t1 ON s1.tid_FK2 = t1.tid
INNER JOIN score s2 ON s1.date=s2.date AND s1.tid_FK1 = s2.tid_FK2 AND s1.tid_FK2 = s2.tid_FK1
INNER JOIN t2 ON s1.tid_FK1 = t2.tid
WHERE s1.tid_FK2 = @teamID
------
(SELECT s.score as myscore,s.teamID_FK as me,s.opp_teamID_FK as them from score s where s.teamID_FK=23)
UNION
(SELECT t.score as theirscore,t.opp_teamID_FK as me,t.teamID_FK as them from score t where t.opp_teamID_FK=23)

yields:

 myscore   	  me   	  them
1770 	23 	25
1210 	23 	30
2080 	23 	29
1970 	23 	25
1650 	23 	30
900 	23 	29

theirscore doesn't even appear!