Getting redundant records $result = $query->entityCondition('entity_type', 'node')
  
  
    ->entityCondition('bundle', 'mypage')
    ->fieldCondition('field_mymodule_module','tid', 123,'=')
     ->execute();
  
  
  $nids = array_keys($result['node']);
  
  $or = db_or();
  
  foreach($nids as $nid)
  
  
    $or->condition('m.entity_id', $nid, '=');
  
  
  $query2 = db_select('metatag', 'm')
  
  
    ->fields('m', array('entity_id', 'revision_id', 'language', 'data'))
    ->condition('m.entity_type', 'node')
    ->condition($or)
    ->orderBy('entity_id')
    ->orderby('revision_id')
    ->execute();
  
  
  while ($record = $query2->fetchAssoc()) {
  
  
dpm($record);

    
    }
  


As you can see in above code, I'm trying to get metadata information of each node. Getting nids of them turns out to be easy. However, when I use those nids to retrieve metadata, I get so many identical ones. That problem persists even after I removed "or" statement from the db_select and hard-coded entity_id, it returns like 10 identical records. Can anyone shed a light on the problem and where I am doing wrong here?
$result = $query->entityCondition('entity_type', 'node')

        -&gt;entityCondition('bundle', 'mypage')
        -&gt;fieldCondition('field_mymodule_module','tid', 123,'=')
        -&gt;execute();

    $nids = array_keys($result['node']);
    $array=array();

    foreach($nids as $nid)

{
    $query2 = db_select('metatag', 'm')

    -&gt;fields('m', array('entity_id', 'revision_id', 'language', 'data')) -&gt;condition('m.entity_type', 'node') 


->condition('m.entity_id', $nid, '=')
->orderBy('entity_id') 
->execute()->fetchAssoc();

$array[]=$query2 

        }

$array contains all fields value.traverese this array.
Hope this will give you result.