protected function sortedQueryPrefix(array $aliases) {

        $sortFields = [];

        $result = $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
                $this->getDriverEscaper()->reserved('subject') . ' ' .
                $this->getDriverEscaper()->dbCommand('FROM') .
                $this->operationSeparator . '(' .
                $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
                $this->getDriverEscaper()->reserved('mainq') . '.' .
                $this->getDriverEscaper()->reserved('subject') .
                $this->getDriverEscaper()->getFieldsSeparator();

        foreach ($aliases as $alias) {
            $sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
                    $this->getDriverEscaper()->reserved('object') . ' ' .
                    $this->getDriverEscaper()->dbCommand('AS') . ' ' . $alias['name'];
        }

        $result .= implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
                . ' ' .
                $this->getDriverEscaper()->dbCommand('FROM') . ' ' .
                ' ( ' . $this->query . ' ) AS mainq ' .
                $this->operationSeparator;

        return $result;
    }