Jump to content


Photo

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


  • Please log in to reply
No replies to this topic

#1 Kingskin

Kingskin
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 04 November 2005 - 01:57 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users