How to do join on Drupal dynamic query Following the documentation on https://www.drupal.org/docs/7/api/database-api/dynamic-queries/joins I have constructed a very simple dynamic query with join:

$query = db_select('node', 'n')
     -&gt;condition('n.uid', $promoter, '=')
     -&gt;condition('n.type', 'campaign', '=')
     -&gt;condition('n.status', '1', '=')
     -&gt;fields('n', array('nid'));
     $query-&gt;join('field_data_field_department', 'd', 'n.nid = d.entity_id');

  $result = $query-&gt;execute();
    foreach ($result as $record) {
      debug($record);
}


and it only returns nids whereas the expected results were nids together with the field_data_field_department field values. What should the correct query.
You're only selecting the nid field, you just need some more:

...
-&gt;fields('n', array('nid'))
-&gt;fields('d', array('fields', 'you', 'want'));