How to use "db_query" instead of "db_select"? I am using "db_select" in a computed field to get an array of values from database (trough an entity reference field - multi value):

$wrapper = entity_metadata_wrapper($entity_type, $entity);
$current_nid = $wrapper-&gt;nid-&gt;value();
$values_y = array();
/* First I get an array of referenced nodes IDs that are neccesary in second query*/
$child = db_select('field_data_field_plan_tpl_select_trainings', 'f')
  -&gt;fields('f', array('field_plan_tpl_select_trainings_target_id'))
  -&gt;condition('entity_type', 'node')
  -&gt;condition('bundle', 'skills_plan_tpl')
  -&gt;condition('entity_id', $current_nid)
  -&gt;execute();
$child_nid = array();
foreach ($child as $item_child){
   $child_nid[] = $item_child-&gt;field_plan_tpl_select_trainings_target_id;
}
/* Here I get an array of values from referenced nodes */
$week_no = db_select('field_data_field_skill_week_no_planned', 'f')
  -&gt;fields('f', array('field_skill_week_no_planned_value'))
  -&gt;condition('entity_type', 'node')
  -&gt;condition('bundle', 'skill')
  -&gt;condition('entity_id', array($child_nid))
  -&gt;execute();
$week_value = array();
foreach ($week_no as $item_week){
   $week_value[] = $item_week-&gt;field_skill_week_no_planned_value;
}

$values_y = array_filter($week_value);


I understand that "db_query" is faster than "db_select"; is it true and can it have a positive impact in my situation? How can this be translated into "db_query"?
db_query can be used with an actual MySQL query - you just insert the MySQL query as you would in, say, PHPMyAdmin or some other UI for MySQL (or command line).

You can also substitute arguments into the query based on the second argument passed to the function, as such (found on Drupal.org as an example):

$result = db_query('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = :uid', array(':uid' =&gt; $uid));


Here the $uid variable is being passed as an argument to the query. Theoretically you could also write this as such:

$result = db_query('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = ' . $uid);


As Clive mentions in the comments though, this is just for illustrative purposes, as it does open you up to potential attack.