A
A
Artur Zenkov2016-02-03 21:36:07
SQL
Artur Zenkov, 2016-02-03 21:36:07

Why does GROUP BY work?

According to the wiki (and others) the code below shouldn't work, but it does. Why?

SELECT title, genre, MAX(checkouts) FROM library_books
GROUP BY genre;

Checked here
In MySQL, it does not work correctly, but also without an error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2016-02-03
@Hrom

will not work in PostgreSQL
What works is the quirks of the DBMS

F
Fet, 2016-02-03
@halenharper

Why shouldn't it work?
Should, just what result you expect.
The response from the database was received, but in the specified example, the values ​​were glued into one line (grouped).

('first', 'comedy', 5),
('second', 'comedy', 7),

and eventually got 2 results as a result of the sample. Without grouping would get 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question