MySQL is a database that has been bending the SQL standard in
ways that make it hard to move off MySQL. What may appear to be a
clever technique for vendor lockin (or maybe just oversight of
the standard) can be quite annoying in understanding the real
meaning of the SQL language.
One such example is MySQL’s interpretation of how GROUP BY
works. In MySQL, unlike any other database, you can put
arbitrary expressions into your SELECT
clause, even
if they do not have a formal dependency on the GROUP
BY
expression. For instance:
SELECT employer, first_name, last_name
FROM employees
GROUP BY employer
This will work in MySQL, but what does it mean? If we only have
one resulting record per employer
, which one of the
employees will be returned? The semantics of the above query is
really this …
[Read more]