Alex  Che
Alex Che

Reputation: 41

select / join / t-sql

I have two tables

NumberOfTeam    NameOfTeam
1               Roma
2               Manchester
3               Inter
4               Milan

Game    FirstTeam   GoalsFirstTeam  SecondTeam  GoalsSecondTeam
1       1           1               2           3
2       3           0               4           0

I need table like this:

Game    FirstTeam   GoalsFirstTeam  SecondTeam  GoalsSecondTeam
1       Roma        1               Manchester  3
2       Inter       0               Milan       0

Can somebody help me with this ?

Upvotes: 0

Views: 67

Answers (1)

Code Different
Code Different

Reputation: 93141

I assume your first table is called Teams and the second Games:

SELECT g.Game,
        t1.NameOfTeam AS FirstTeam,
        g.GoalsFirstTeam,
        t2.NameOfTeam AS SecondTeam,
        g.GoalsSecondTeam
FROM Games g
INNER JOIN Team t1 ON g.FirstTeam = t1.NumberOfTeam
INNER JOIN Team t2 ON g.SecondTeam = t2.NumberOfTeam

Upvotes: 2

Related Questions