How does MySQL decide which identifier is returned in group by clause?

Like this one:

SELECT id, count (*), company FROM jobs COMPANY GROUP BY

Where id is the primary key jobs

+3
source share
1 answer

A similar question:

Why does MySQL allow "group by" queries WITHOUT aggregate functions?

It is MySQL specific and is not standard ANSI SQL. Most other database engines do not allow columns that are not grouped or run through an aggregate function.

MySQL seems to store the value of the first row that matches the criteria.

, , FIRST(), MySQL , , -, , , .

SQL- ANSI :

SELECT FIRST(jobtitle), company FROM jobs GROUP BY company;

MySQL ( ANSI ):

SELECT jobtitle, company FROM jobs GROUP BY company;
+2

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


All Articles