How do I remove JOIN in hook_views_query_alter()? I have a view with two filters (A + B). Filter B should only be included in the query, if a specific value in filter A is set (like a "conditional filter").

So I tried to remove the where condition of filter B in hook_views_query_alter by unsetting it:

if($remove_filter_B){
  foreach ($query-&gt;where as $condition_group_key =&gt; &amp;$condition_group) {
    foreach ($condition_group['conditions'] as $condition_key =&gt; &amp;$condition) {
      if($condition['field'] == 'field_B_to_remove'){
        unset($condition_group['conditions'][$condition_key]);
        break;
      }
    }
  }
}


I successfuly removed the where clause but the INNER JOIN on the table of filter B is still part of the query. How can I remove it? I've tried unset($query-&gt;tableQueue['node__field_B_to_remove']) but this doesn't work because tableQueue is protected.

Maybe I'm going the wrong way. Basicly I just want to have a "conditional filter". 

Some aditional info: The view lists nodes of two different types. You can filter those node types with filter A. The field of filter B only exists in one of the node types. So if you choose filter B you only get nodes of one type. And when you select the other one in filter A you get no result. And that's the issue.
you can add field B as a relationship and use as a reference term in your View UI