Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.