O
O
Optimus2016-11-28 13:32:23
MySQL
Optimus, 2016-11-28 13:32:23

How to get max. values ​​when grouping MySQL?

A query without grouping gives this result. On the left id on the right is the quantity.
VLFY1sKpfgg.jpg
If you group GROUP BY id, then the amount is not the maximum in the result. I don’t know how to sort before grouping, because ORDER BY must come after GROUP BY and it already contains the minimum values ​​and in the singular.
UP:

SELECT table1.id, table2.members
FROM table1
INNER JOIN table2 ON table2.id = table1.id WHERE table2.members > 400 GROUP BY id

Нужна запись с максимальным значением members но только среди тех записей где members > 400

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-11-28
Pyan @marrk2

Агрегатные функции - MAX()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question