Getting Two items from Same table in SELECT statment

Posted by mouthpiec on Stack Overflow See other posts from Stack Overflow or by mouthpiec
Published on 2010-04-17T18:49:24Z Indexed on 2010/04/17 18:53 UTC
Read the original article Hit count: 154

Filed under:
|

Hi,

I an SQL SELECT statement I need to extract the name of two teams, taking both teams from the same table. Eg Below

SELECT sport_activity_id, (team A), (team B), date, time 
FROM sportactivity, teams 
WHERE competition_id_fk = 2

For (team A) and (team B) I have an team_id, which is a FK for the table 'teams'

Is it possible to get the following result from these tables by SQL? 1, Barcelona, Arsenal, 01/01/2000, 20:00

the two table are the following:

table sportactivity

sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time

(tuple example) -> 1, 33, 41, 5, 2010-04-14, 05:40:00

table teams

team_id, team_name

(tuple example) -> 1, Algeria

© Stack Overflow or respective owner

Related posts about sql

Related posts about select