How to sort by a fields content?
You shouldn't query the database directly for entity data, there are APIs for that.

In this case you need an EntityFieldQuery:

$query = new \EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'node')
  -&gt;propertyCondition('type', 'team_member')
  -&gt;propertyCondition('status', 1)
  -&gt;fieldOrderBy('field_last_name', 'value');

$result = $query-&gt;execute();
if (isset($result['node'])) {
  $nids = array_keys($result['node']);
}