NotionCommotion Posted September 5, 2016 Share Posted September 5, 2016 I had been using the following script, but question whether I should bother as MySQL will not return duplicates. Is it better to just send MySQL everything, and let it deal with it? $input=[5,3,null,7,5,3,2]; if($input=array_values(array_filter(array_unique($input)))){ //Remove non-unique values, null values, and reorder $list=rtrim(str_repeat('?,',count($input)),','); $sql="SELECT a,b,c FROM my_table WHERE id IN ($list)"; //my_table.id has a NOT NULL constraint $stmt = $this->db->prepare($sql); $stmt->execute($input); } Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted September 6, 2016 Solution Share Posted September 6, 2016 If the list has only constant values then it will be sorted and MySQL will do a binary search (->). That's one additional comparison every time you double the size of the list. While not a big difference, I'd remove them: one pass in PHP to remove vs. however-many additional comparisons in MySQL. Quote Link to comment 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.