title: Drupal Multi-Join Query
body: <p>I am having trouble creating a multi-join mysql query in drupal. Here's my code: </p>
  
  <pre><code>if ($params['mobile_app']) {
    if (isset($params['mobile_app_date'])) {
      $query-&gt;join('field_data_field_on_mobile_app', 'm', 'm.entity_id = n.nid');
      $query-&gt;join('field_data_field_mobile_app_date', 'm', 'm.entity_id = n.nid');
      $query
        -&gt;condition('m.field_on_mobile_app_value', 1)
        -&gt;condition('m.field_mobile_app_date_value', dosomething_helpers_convert_date($params['mobile_app_date']), '&lt;=')
        -&gt;condition('m.field_mobile_app_date_value2', dosomething_helpers_convert_date($params['mobile_app_date']), '&gt;=');
    } else {
      $query-&gt;join('field_data_field_on_mobile_app', 'm', 'm.entity_id = n.nid');
      $query-&gt;condition('m.field_on_mobile_app_value', 1);
    }
  }
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'm.field_mobile_app_date_value' in 'where clause'"
  </code></pre>
  
  <p>It's interesting though because when separated, the queries work fine. It's just when I try to combine them, it breaks. Anyone know what I'm doing wrong?</p>
  
  <p>Separate queries (works): </p>
  
  <ul>
  <li>?mobile_app=1</li>
  <li>?mobile_app_date=2015-10-01</li>
  </ul>
  
  <p>Combined (doesn't work):</p>
  
  <ul>
  <li>?mobile_app=1&amp;mobile_app_date=2015-10-01</li>
  </ul>