Query between 2 tables
SelectQuery::join() returns the alias created, not the query object, so it can't be chained. This should work

$query = db_select('users','u')
 -&gt;fields('u',array('uid'))
 -&gt;fields('r',array('rid'))
 -&gt;condition('r.rid', '3', '=')
 -&gt;orderBy('login', 'DESC')
 -&gt;range(0,1);

$query-&gt;join('users_roles','r','r.uid = u.uid');
$res = $query-&gt;execute();