diff --git a/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc b/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc
index ab51961..7d9a804 100644
--- a/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc
+++ b/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc
@@ -99,29 +99,43 @@ class views_handler_argument_term_node_tid_depth extends views_handler_argument
       $operator = "=";
       $tids = $this->argument;
     }
-    // Now build the subqueries.
-    $subquery = db_select('taxonomy_index', 'tn');
-    $subquery->addField('tn', 'nid');
-    $where = db_or()->condition('tn.tid', $tids, $operator);
-    $last = "tn";
 
     if ($this->options['depth'] > 0) {
-      $subquery->leftJoin('taxonomy_term_hierarchy', 'th', "th.tid = tn.tid");
-      $last = "th";
-      foreach (range(1, abs($this->options['depth'])) as $count) {
-        $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.parent = th$count.tid");
-        $where->condition("th$count.tid", $tids, $operator);
-        $last = "th$count";
+      $tids = is_array($tids) ? $tids : array($tids);
+      foreach ($tids as $tid) {
+        $term = taxonomy_term_load($tid);
+        if (!empty($term)) {
+          $tree = taxonomy_get_tree($term->vid, $term->tid, (int) $this->options['depth']);
+          $tids = array_merge($tids, array_map('_taxonomy_get_tid_from_term', $tree));
+        }
+      }
+      if (count($tids) > 1) {
+        $operator = 'IN';
+      }
+      else {
+        $tids = current($tids);
+        $operator = '=';
       }
     }
     elseif ($this->options['depth'] < 0) {
-      foreach (range(1, abs($this->options['depth'])) as $count) {
-        $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.tid = th$count.parent");
-        $where->condition("th$count.tid", $tids, $operator);
-        $last = "th$count";
+      $tids = is_array($tids) ? $tids : array($tids);
+      foreach ($tids as $tid) {
+        $tids = array_merge(taxonomy_get_parents_all($tid), $tids);
+      }
+      if (count($tids) > 1) {
+        $operator = 'IN';
+      }
+      else {
+        $tids = current($tids);
+        $operator = '=';
       }
     }
 
+    // Now build the subqueries.
+    $subquery = db_select('taxonomy_index', 'tn');
+    $subquery->addField('tn', 'nid');
+    $where = db_or()->condition('tn.tid', $tids, $operator);
+    $last = "tn";
     $subquery->condition($where);
     $this->query->add_where(0, "$this->table_alias.$this->real_field", $subquery, 'IN');
   }
