How to display all record from database in Drupal? global $user;
$nid = '650';


$query = db_select('field_data_field_batch_reference');
$query-&gt;fields('field_data_field_batch_reference', array('field_batch_reference_target_id'));
$query-&gt;condition('entity_id', $nid, '=');
$result = $query-&gt;execute()-&gt;fetchField();
drupal_set_message($result);
You should use a different method on the query object to get all results.

e.g fetchCol() to get an array when querying for a single column value (in this case field_batch_reference_target_id):

global $user; 
$nid = '650';

$query = db_select('field_data_field_batch_reference');
$query-&gt;fields('field_data_field_batch_reference', array('field_batch_reference_target_id'));
$query-&gt;condition('entity_id', $nid, '=');
$target_ids = $query-&gt;execute()-&gt;fetchCol();
drupal_set_message('&lt;pre&gt;' . var_export($target_ids, 1) . '&lt;/pre&gt;);


You could also then load those entities with something like

$entities = entity_load_multiple('entity_type', $target_ids);
drupal_set_message('&lt;pre&gt;' . var_export($entities, 1) . '&lt;/pre&gt;);


Keep in mind that will load all results, so you may want to add a limit to your query instead, e.g:

$query-&gt;range(0, 25);