Kingskin Posted November 4, 2005 Share Posted November 4, 2005 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? Quote Link to comment https://forums.phpfreaks.com/topic/2799-distinct-doesnt-seem-to-be-working-help-please/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.