zend-frameworkzend-db-select

Remove "DISTINCT" from Zend_Db_Select


You can add "DISTINCT" with the distinct() method. But is there any way to remove it after it is added?


Solution

  • The distinct method accepts a parameter $flag(bool). Setting it to false will disable the distinct from the query. Check

    Zend/Db/Select.php Line 192

    /**
         * Makes the query SELECT DISTINCT.
         *
         * @param bool $flag Whether or not the SELECT is DISTINCT (default true).
         * @return Zend_Db_Select This Zend_Db_Select object.
         */
        public function distinct($flag = true)
        {
            $this->_parts[self::DISTINCT] = (bool) $flag;
            return $this;
        }
    

    NB This is for Zend 1.12