0

i have two tables in mySQL:

Table 1: Club(ClubID=PK, club_name)

Table 2: League_table(tableID=PK, position, clubID=fk, games_played, points)

how would i join the two tables to give a query that displayed only

(position, club-name, games_played)

1

3 Answers 3

2

Simple join:

select l.position, c.club_name, l.games_played
from club c, league_table l 
where l.clubid=c.clubid
Sign up to request clarification or add additional context in comments.

Comments

1

You are looking for a left join. ClubID is the foreign key (the column "connecting" the two tables).

select position, club_name, games_played
from league_table
left join club on club.ClubId = league_table.clubID

Comments

0

select a.club_name, b.position, b.games_played from club as a join league_table as b on a.clubid=b.clubid Thats what you want.

@Alexen: No need of left join in this case.

@Diegoe: one friendly advise, always use on in join, without it query goes slow down when you are working on big tables.

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.