function setTable($table_name, $alias = null) {
		if ($table_name instanceof Query) {
			if (!$alias) {
				throw new RuntimeException('The nested query must have an alias.');
			}
			$table_name = clone $table_name;
		} elseif (null === $alias) {
			$space = strrpos($table_name, ' ');
			$as = strrpos(strtoupper($table_name), ' AS ');
			if ($as != $space - 3) {
				$as = false;
			}
			if ($space) {
				$alias = trim(substr($table_name, $space + 1));
				$table_name = trim(substr($table_name, 0, $as === false ? $space : $as));
			}
		}

		if ($alias) {
			$this->setAlias($alias);
		}

		$this->table = $table_name;
		return $this;
	}