MySQL SELECT WHERE IN LIST and NOT IN LIST in the same SQL
I have this: $ids = "1,2,3,4,5"; $sqlQuery = "SELECT id, moderation_date FROM table_live WHERE id IN (".$ids.")"; $q = $this->CI->db->query($sqlQuery); if($q->num_rows() > 0) { foreach ($q->result() as $row) { $arr[] = $row; } } return $arr; This is just working fine if all ids exist in table_live and return array([id] => 1 [moderation_date] => 2012-04-11 12:55:57).... The problem: If I send a list of ids 1-2-3-4-5 where only 1-2-5 match the IN LIST clause I need to return all in list and for those don't match the list a null value. array([id] => 3 [moderation_date] => null) generate an outer