galvin Posted November 10, 2012 Share Posted November 10, 2012 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)"; Quote Link to comment https://forums.phpfreaks.com/topic/270551-in-and-how-it-handles-duplicates/ Share on other sites More sharing options...
kicken Posted November 10, 2012 Share Posted November 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270551-in-and-how-it-handles-duplicates/#findComment-1391618 Share on other sites More sharing options...
galvin Posted November 12, 2012 Author Share Posted November 12, 2012 Thanks for confirming, kicken. I think I should be able to "duplicate" things in the PHP code, as you suggested, so I'll give that a try first. If I struggle I'll explain more what I need to do. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/270551-in-and-how-it-handles-duplicates/#findComment-1391829 Share on other sites More sharing options...
fenway Posted November 13, 2012 Share Posted November 13, 2012 Yeah, that would make no sense based on set theory -- I'm curious as to why you'd actually want to do this. Quote Link to comment https://forums.phpfreaks.com/topic/270551-in-and-how-it-handles-duplicates/#findComment-1391940 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.