How can i get the value from the Dynamic query $query=db_select('node','n');
$query-&gt;join('field_data_field_cmp_playerid','b','n.nid=b.entity_id');
$query-&gt;join('field_data_field_cmp_id','c','n.nid=c.entity_id');
$query-&gt;join('field_data_field_cmp_userscore','d','n.nid=d.entity_id');
$query-&gt;join('field_data_field_cmp_usersupport','e','n.nid=e.entity_id');
$query-&gt;join('field_data_field_cmp_status','f','f.entity_id=c.field_cmp_id_nid');
$query-&gt;join('field_data_field_cmp_attend_time','g',' g.entity_id = n.nid');
$query-&gt;join('field_data_field_cmp_end_date','h',' h.entity_id = c.field_cmp_id_nid');
$query-&gt;fields('n',array('title','nid'),'d',array('field_cmp_userscore_value'),'e',array('field_cmp_usersupport_value'),'f',array('feld_cmp_status_tid'),'g',array('.field_cmp_attend_time_value'),'h',array('field_cmp_end_date_value'));
$query-&gt;condition('b.field_cmp_playerid_uid',$userid,'=');
$query-&gt;condition('n.type','Campaign_PlayerList','=');
$result=$query-&gt;execute()-&gt;fetchAll();


i use foreach loop to get the value of the query

foreach($result as $value)
{
    drupal_set_message(t('The variable is %va',array('%va'=&gt;$value-&gt;title)));
    drupal_set_message(t('The variable is %va1',array('%va2'=&gt;$value-&gt;field_cmp_userscore_value)));
    drupal_set_message(t('The variable is %va2',array('%va2'=&gt;$value-&gt;field_cmp_end_date_value)));
}


the value i get is  "title" and i can't get the field_cmp_userscore_value and field_cmp_end_date_value value.

what could the problem be? 

Thank you
The problem is that the following line is wrong:

$query-&gt;fields('n',array('title','nid'),'d',array('field_cmp_userscore_value'),'e',array('field_cmp_usersupport_value'),'f',array('feld_cmp_status_tid'),'g',array('.field_cmp_attend_time_value'),'h',array('field_cmp_end_date_value'));


You need to call fields() separately for each table. Right now, the additional arguments are ignored.

Also note that it is strongly recommended to use EntityFieldQuery to query field tables, that however has the limitation that you need to load the node object to get the field values.