Jump to content

Archived

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

Kingskin

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

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?

Share this post


Link to post
Share on other sites

×

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.