Jump to content

In And How It Handles Duplicates


galvin

Recommended Posts

Say you are running a query using IN and the ids you are "looking in" contain duplicates. See example below where there are three "4"s. It seems like IN is ignoring the "extra" 4s because I am only getting the info that goes with ID #4 ONCE (so I assume IN ignores duplicates by default)

 

Regardless, how can I make it so I do in fact get the info for ID #4 returned three times? Is that possible, or should I approach it differently?

 

$q="SELECT *  FROM  players  WHERE playerid IN (1,2,3,4,4,4,5,6)";

Link to comment
Share on other sites

Yes, it will only return a matching row once regardless of how many times it's value appears in the IN clause.  No, afaik there is no way to change that.  If you need it multiple times, you'll have to do that after the fact in your PHP code.  Select each row's data then duplicate it when you read the results if necessary.

 

It may be helpful to describe what exactly you're trying to do, perhaps someone can provide a better approach.

 

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.