I am trying to create a query in a table that has some 500,000 records and some 50 or 60 columns. What I need is to collate these records into groups and select the max record in each group.
To simplify the problem I have a table as follows
+----+-------------+----------+--------+
| id | external_id | group_id | mypath |
+----+-------------+----------+--------+
| 1 | 1003 | 1 | a |
| 2 | 1004 | 2 | b |
| 3 | 1005 | 2 | c |
+----+-------------+----------+--------+
The simple group by is as follows
select * from temp GROUP BY group_id
which returns
+----+-------------+----------+--------+
| id | external_id | group_id | mypath |
+----+-------------+----------+--------+
| 1 | 1003 | 1 | a |
| 2 | 1004 | 2 | b |
+----+-------------+----------+--------+
Nice but not what I want. What I want is the entire record for max enternal_id in each group. In other words
+----+-------------+----------+--------+
| id | external_id | group_id | mypath |
+----+-------------+----------+--------+
| 1 | 1003 | 1 | a |
| 3 | 1005 | 2 | c |
+----+-------------+----------+--------+
Somehow I am looking to put a max(external_id) statement in here to filter what is needed but so far all my investigation has failed. Some guidance would be appreciated. It is important that when returning the max(external_id) that the entire record is selected as the path column differs.