public function toSql()
    {
        return implode(' ', array_filter(array(
            $this->_clause(($this->_distinct
                ? 'SELECT DISTINCT' : 'SELECT'), $this->_select),
            $this->_clause('FROM', $this->_from),
            implode(' ', $this->_joins),
            $this->_clause('WHERE', $this->_where),
            $this->_clause('GROUP BY', $this->_group),
            $this->_clause('HAVING', $this->_having),
            $this->_clause('ORDER BY', $this->_order),
            $this->_limit,
            $this->_lock
            )));
    }