SQLite: GROUP BY without aggregate

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?

+4
source share
1 answer

This is mistake.

which was installed more than ten years ago; SQLite 2.8.17 was launched in 2005. You should reconsider your choice of software.

+2
source

Source: https://habr.com/ru/post/1672585/


All Articles