2

I have table team which contains columns like this

team_id | name    | competition_id
--------+---------+------
 1      | name 1  | 10
 2      | name 2  | 10

and also i have this table fixtures

fixture_id  | home_team_id | away_team_id | competition_id
    --------+--------------+--------------+--------------
     1      | 1            | 2            | 10
     2      | 2            | 1            | 10 

Primary key for table fixtures is fixture_id, home_team_id, away_team_id, and competition_id. Also home_team, away_team and competition are foreign keys.

How can I select home_team_name , away_team_name, from fixtures.

2
  • What is the question? Commented Sep 23, 2015 at 17:10
  • How can I select home_team_name, away_team_name, using join or where clause ? Commented Sep 23, 2015 at 17:12

1 Answer 1

3

You can join the fixtures table on the teams table twice - one for the home team and one for the away team:

SELECT  fixture_id, home.name, away.name
FROM    fixtures f
JOIN    teams home on home.team_id = f.home_team_id
JOIN    teams away on away.team_id = f.way_team_id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.