Select with INNER JOIN in Three mysql tables

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Select with INNER JOIN in Three mysql tables

Now i have my next problem & can`t find out what i must do to complete.
I have three mysql tables:
user

Code: Select all

Type	Collatie	Attributen	Leeg	Standaardwaarde	Extra	Actie
1	user_id	int(11)			Nee	0		
2	user_email	varchar(255)	utf8_general_ci		Nee	Geen		
3	user_password	varchar(255)	utf8_general_ci		Nee	Geen		
4	user_firstname	text	utf8_general_ci		Nee	Geen		 
5	user_lastname	text	utf8_general_ci		Nee	Geen
group

Code: Select all

Type	Collatie	Attributen	Leeg	
1	group_id	int(11)			Nee	Geen		 
2	club_id	int(11)			Nee	Geen		 
3	mem_id	int(11)			Nee	Geen	

Code: Select all

club
Type	Collatie	Attributen	
1	club_id	int(11)			
2	club_name	varchar(50)
I hope my English is understandble (lol).

I try to find out how i can add the club_name (from the third table) with the user_firstname, user_lastname.
I wanna use with this code, I understand it not quite & keep on learning, and it is resulted a Select like this.

Code: Select all

$sql = "SELECT A.`user_firstname` , A.`user_lastname` , B.`mem_id` , B.`club_id` , C.`club_name` , C.`club_id`
FROM `user`AS A
INNER JOIN `group` AS B
ON B.`mem_id` = A.`user_id` 
INNER JOIN `club` AS C 
ON B.`club_id` = C.`club_name` ";

Admin Posts: 805
Hello
Try with this code (see the relations with the IDs between tables):

Code: Select all

$sql = "SELECT A.`user_firstname`, A.`user_lastname`, B.`mem_id`, B.`club_id`, C.`club_name`
FROM `user`AS A
INNER JOIN `group` AS B
ON B.`mem_id` = A.`user_id` 
INNER JOIN `club` AS C 
ON B.`club_id` = C.`club_id`";

Similar Topics