Jump to content

Issue with left join query


this.user

Recommended Posts

I have three tables

 

team

id

 

player

team_id

 

 

supply

team_id

 

player table has the following data:  Mike, tom, john, joe

 

supply table has the following data:  bat, glove, hat

 

when i run this query, i get repeat values back, how do i make this unique, so each value from each table appears once.

 

'SELECT DISTINCT 
									team.*, player.name, supply.name
								 FROM
								 	team
									LEFT JOIN player ON(player.team_id=team.id)
									LEFT JOIN supply ON(supply.team_id=team.id)
								 WHERE
								 	team.id="43"';

 

 

player:

 

mike, mike, mike, tom, tom, tom, jon, jon, jon, joe, joe, joe

 

supply:

 

bat, glove, hat, bat, glove, hat, bat, glove, hat, bat, glove, hat

 

i would like this result instead

 

player:

 

mike, tom, jon, joe

 

 

supply:

 

bat, glove, hat

Link to comment
https://forums.phpfreaks.com/topic/229734-issue-with-left-join-query/
Share on other sites

Hi

 

What it has brought back is each player several times, once for each piece of equipment. As each row will have a player and a piece of equipment I do not see how you intend to have 4 players and 3 pieces of equipment.

 

I looks like what you need is 2 separate queries.

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.