code: private function asScalarSubQuery($callback, $default = false) 
  	{
  		$sql = $this->sql;
  		
  		$this->sql = $callback($sql);
  		$result = $this->queryScalar(null);
  		$this->sql = $sql;
  		
  		return (is_null($result) ? $default : $result);
  	}
docs: Execute this query as a sub query of another query that must return a scalar value.
  @param callable $callback Callback to use to create the new query. Callback must be
  of format string func(string), where the param is the current query and return value is
  the new query to execute.
  @param mixed $default Default value to return on failure.
  @return bool|mixed