public function formatSubQuery(SubQuery $query) {

        // Reset the alias since statement would have double aliasing
        $alias = $query->getAlias();
        $query->asAlias(null);

        // @codeCoverageIgnoreStart
        if (method_exists($this, 'buildSelect')) {
            $output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
        } else {
            throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
        }
        // @codeCoverageIgnoreEnd

        if ($alias) {
            $output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
        }

        if ($filter = $query->getFilter()) {
            $output = $this->getKeyword($filter) . ' ' . $output;
        }

        return $output;
    }