Page 1 of 1

Select with INNER JOIN in Three mysql tables

Posted: 12 Jan 2017, 11:58
by JanMolendijk
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` ";

Select with INNER JOIN in Three mysql tables

Posted: 12 Jan 2017, 13:42
by Admin
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`";