zend-framework2zend-dbzend-db-select

How to use distinct in Zend Framework 2?


How can I use the distinct clause with Zend\Db\Sql\?


Solution

  • Use an expression in your column selection.

    $select = new Select('tablename');
    $select->columns(array(new Expression('DISTINCT(id) as id')));