I am facing an issues while using DISTINCT query in paginator DbSelect adapter in ZF2. My steps are.
First I created Select object.
$select = new Select();
$select->columns(
array(
'personId' => new Expression("DISTINCT $this->table.person_id"),
'first_name', 'middle_name', 'last_name'));
$select->from($this->table);
Then I passed this object to Zend\Paginator\Adapter\DbSelect
$result = new DbSelect($select, $this->adapter, $this->resultSetPrototype);
Now issue is that If I print sql query via
echo str_replace('"', '', $select->getSqlString());
and run this query on mysql it shows 12 results.
But $result->count();
shows 55 result.
I have tried to figure out the problem and found that perhaps Zend\Paginator\Adapter\DbSelect count()
function is buggy.
When I printed sql query in Zend\Paginator\Adapter\DbSelect count()
function it removes the DISTINCT clause from query and added its own count column c.
SELECT COUNT(1) AS c FROM myTable;
Please suggest what should I do?