Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lordzsolt
Starting Member
3 Posts |
Posted - 2011-11-16 : 01:09:14
|
| Hey there, we have quite a problem here at science class. We have two tables:First table(table1): - date of a football match (date)- Team one's number (t1)- Team two's number (t2)Second Table: (table2)- Name of a team (name)- Number of a team (number)So we have to show which team played with Germany (or other team).The thing is, we can do it by showing the number of the teams (t1,t2), but we'd have to show the names of the teams, which not even my teacher knows how to do. Any ideas? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 01:21:28
|
| join to second table twice based on team one and team two number values and select name fields------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lordzsolt
Starting Member
3 Posts |
Posted - 2011-11-16 : 01:25:13
|
| Could you post the SQL code for it please? (I didn't really get the connections lesson) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 01:31:25
|
| first make a try based on my explanation (i'm sure thats quite straightforward if you know concept of joins). If you hit a roadblock, post query used and then we will help.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lordzsolt
Starting Member
3 Posts |
Posted - 2011-11-16 : 01:38:28
|
| This is what I got to:Select name as TeamOne, name as TeamTwo, datefrom table1, table2Where (name="Germany" and t1=number and name="France" and t2=number)I kinda don't get the concept of joins, that's why I asked for the code. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 01:47:22
|
you've not joined to table2 twice as i suggestedsee how to do it belowSelect a.date, b.Name AS TeamOne,b1.Name AS TeamTwofrom table1 ainner join table2 bon b.number = a.t1inner join table2 b1on b1.number = a.t2 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|