how to fetch result into array or how to fetch 'nid' out of result?
The simplest way would be:

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

if (!empty($results['node'])) {
  $nids = array_keys($results['node']);
}


There are a few different ways to get the first nid out of the array if that's what you need; personally I prefer reset() as it's non-destructive to the original array (unlike array_shift() for example).

$first_nid = reset($nids);


If you then need the node objects you can pass that array straight to node_load_multiple():

$nodes = node_load_multiple($nids);