I'm trying to understand a strange behaviour 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 GROUP BY behaviour is to merge several rows into one. Without using an aggregate function, it should give me an error or pick a random value for each rows that is nor in GROUP BY nor in aggregate function.
The result seems to be different from what I understand.
Can someone explain me what I'm missing here ?