I am trying to understand the strange behavior of GROUP BY on SQLite v2.8.17
Here is the code:
<?php
$selectMaxQuery = $this->_db->prepare('SELECT COUNT(*) AS c FROM (SELECT MAX(groupCode) FROM docs GROUP BY groupCode)');
$selectQuery = $this->_db->prepare(' SELECT COUNT(*) AS c FROM (SELECT groupCode FROM docs GROUP BY groupCode)');
$selectMaxQuery->exec();
$selectQuery->exec();
var_dump($selectMaxQuery->fetch()->c, $selectQuery->fetch()->c);
Here is the result:
string(3) "614"
string(3) "797"
Everywhere I go on the Internet, it says that the behavior of GROUP BY is to combine several lines into one. Without using an aggregate function, he should give me an error or select a random value for each row, which is neither GROUP BY nor in the aggregate function.
The result seems different from what I understand.
Can someone explain to me what I am missing here?
zenko source
share