Drupal db_select join 3 fields I want join to my select three fc fields:


field_data_field_show_block_carousel
field_data_field_poster_film
field_data_field_film_link


I try this:

$nids = db_select('node', 'n');
  $nids-&gt;join(array('field_data_field_show_block_carousel', 'field_data_field_poster_film', 'field_data_field_film_link',), 'fc', 'n.nid = fc.entity_id');
  $nids-&gt;fields('fc', array('field_poster_film_fid','field_film_link_url',));
  $nids-&gt;fields('n', array('nid', 'title', 'uid',))
    -&gt;condition('n.type', 'vodeo_library')
    -&gt;condition('fc.field_show_block_carousel_value', 1)
    -&gt;execute(); // returns an indexed array
  $result = $nids-&gt;execute()-&gt;fetchAllAssoc('nid');


but recived sql error? pls tell me what I do wrong?
You should try to write each join on a new line, not as an array. See Joins and public function SelectQuery::join.

So try it like this:

$nids = db_select('node', 'n');
  $nids-&gt;join('field_data_field_show_block_carousel', 'fc', 'n.nid = fc.entity_id');
  $nids-&gt;join('field_data_field_poster_film', 'fp', 'n.nid = fp.entity_id');
  $nids-&gt;join('field_data_field_film_link', 'fl', 'n.nid = fl.entity_id');
  $nids-&gt;fields('fp', array('field_poster_film_fid'));
  $nids-&gt;fields('fl', array('field_film_link_url'));
  $nids-&gt;fields('n', array('nid', 'title', 'uid',))
    -&gt;condition('n.type', 'vodeo_library')
    -&gt;condition('fc.field_show_block_carousel_value', 1)
    -&gt;execute(); // returns an indexed array
  $result = $nids-&gt;execute()-&gt;fetchAllAssoc('nid');


Depending on what your module attempts to achieve, you might also want to have a look at the default Drupal functions for attaching fields to nodes (you only have a condition on one field):


field_attach_load()
field_get_items()
field_view_value()


You can get a rendered field value like this:

$node = node_load($nid);
$poster= field_get_items('node', $node, 'field_data_field_poster_film');
$output = field_view_value('node', $node, 'field_data_field_poster_film', $poster[0]);


And if you don't mind a little overhead, you might want to try an EntityFieldQuery. It will give you all fields and is a little slower then a regular SQL query, but is much easier to read and change.

$query = new EntityFieldQuery();

$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', 'vodeo_library')
  -&gt;propertyCondition('status', NODE_PUBLISHED)
  -&gt;fieldCondition('field_show_block_carousel_value', 'value', 1, '=');

$result = $query-&gt;execute();

if (isset($result['node'])) {
  $news_items_nids = array_keys($result['node']);
  $news_items = entity_load('node', $news_items_nids);
}