Log in

View Full Version : Fetch and match two tables



queerfm
03-27-2009, 02:55 PM
Hi I have two tables that i need to be able to show the username when fetching data from table 2

Table 1 is called - team
the rows are:
id
teamname
teamlogo

in Table 2 - this table has the rounds so each team playing each other
The rows:
id - Match ID
team1 - Team A (this gets the ID from the first table)
team2 - Team B (this gets the ID from the first table)

However when I want to show the names of the team that is versing each other because the team names are not in table 2 I cant show them.

Can any one tell me how I get these two tables to communicate please.

CrazyChop
03-28-2009, 06:58 AM
I can't do it in one SQL statement (maybe a SQL expert could come along)

First, retrive the team-ids

select team1, team2 from table1, table2 where table1.id = table2.id

Them get the names

select teamname from table1 where id = $teamidID

(note, $teamID is a variable)

For some reasons, I don't think a combined SQL is possible. If it does, it is going to be one heck of a complicated one. I'll check around.