public function buildSQL($union=false) {
		$params = [];

		list($tables, $tableparams) = $this->buildTables();
		$params = array_merge($params, $tableparams);

		list($columns, $columnsparams) = $this->buildColumns();
		$params = array_merge($params, $columnsparams);

		list($jointures, $joinparams) = $this->buildJointures();
		$params = array_merge($params, $joinparams);

		list($where, $whereparams) = $this->buildWhere();
		$params = array_merge($params, $whereparams);

		list($groupBy, $groupByParams) = $this->buildGroupBy();
		$params = array_merge($params, $groupByParams);

		list($having, $havingparams) = $this->buildHaving();
		$params = array_merge($params, $havingparams);

		if(!$union) {
			$limit = $this->buildLimit();

			list($orderBy, $orderByParams) = $this->buildOrderBy();
			$params = array_merge($params, $orderByParams);
		}
		else
			$orderBy = $limit = '';

		$unions = '';
		foreach($this->unions as $union) {
			$unions .= "\n".'UNION ('.$union->buildSQL(true).')';
			$params = array_merge($params, $union->getParameters());
		}

		$sql = 'SELECT '.$columns.' FROM '.$tables.$jointures.$where.$groupBy.$having.$unions.$orderBy.$limit;

		$this->replaceArrayParams($sql, $params);
		$this->replaceRaws($sql, $params);

		$this->params = $params;

		return $sql;
	}