Jump to content

DISTINCT doesn't seem to be working - Help please!


Kingskin

Recommended Posts

Hi,

 

I've got some code which builds a query based on search results. I have an array of IDs called $player_ids, and the code builds the WEHRE clause based on that:

 

foreach ( $player_ids as $output )
       {
       $sql .= " || episode_player.player_id = $output";
       }
     	
     	$sql = substr($sql,4);

 

I then build my query as follows:

$query = "SELECT DISTINCT *
          FROM episode
          INNER JOIN episode_player
          ON episode.id = episode_player.ep_id
          WHERE $sql
          ";

 

This is working OK, and my final query looks something like this (obviously dependant on search results):

 

SELECT DISTINCT * 
FROM episode 
INNER JOIN episode_player 
ON episode.id = episode_player.ep_id 
WHERE episode_player.player_id = 61 || episode_player.player_id = 36 || episode_player.player_id = 63 || episode_player.player_id = 62 || episode_player.player_id = 83 || episode_player.player_id = 31 || episode_player.player_id = 96 || episode_player.player_id = 16 || episode_player.player_id = 40 || episode_player.player_id = 104 || episode_player.player_id = 54 || episode_player.player_id = 53 || episode_player.player_id = 87 || episode_player.player_id = 9 || episode_player.player_id = 5 || episode_player.player_id = 7 || episode_player.player_id = 24 || episode_player.player_id = 56 || episode_player.player_id = 85 || episode_player.player_id = 73 || episode_player.player_id = 93

 

However, when I come to extract the results from this query, I find that there are duplicate rows. I don't see how this can be as i've used DISTINCT, but it just doesn't seem to be doing anything.

 

Can anyone shed any light on this for me please?

Link to comment
Share on other sites

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.