How to get max values when you group MySQL?

The query without grouping gives such a result. Left right id number.

If you group BY GROUP id the number of hits the maximum in the result. Sort before grouping don't know how because the ORDER BY should come after GROUP BY, and it already receives the minimum values and singular.

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

The desired entry with the maximum value among members but only those records where the members > 400
July 2nd 19 at 13:34
2 answers
July 2nd 19 at 13:36
Aggregate functions - MAX()
Yes, I understand, but do not understand how to use it updated the question - Tyreek.Stoke commented on July 2nd 19 at 13:39
SELECT `id`, MAX(`members`) AS `max_members`
 FROM `table`
 WHERE `members` > 400
 GROUP BY `id`

SELECT `id`, MAX(`members`) AS `max_members`
 FROM `table`
 GROUP BY `id`
 HAVING `max_members` > 400
- Kenyatta commented on July 2nd 19 at 13:42
July 2nd 19 at 13:38
select id, max(quantity) from some_table group by id;
Updated the question, put the query that works now. I guess that you MAX() to use but how to insert MAX after the WHERE clause? Need maximum one entry but only among those that > 400 I Have every syntactic climbs... - Tyreek.Stoke commented on July 2nd 19 at 13:41
select, max(table2.members) from table1 inner join table2 using(id) group by id having max(table2.members) > 400;
- Kenyatta commented on July 2nd 19 at 13:44

Find more questions by tags MySQLSQL