Let's suppose we have a simple table users:
id | name | company | other columns.......
----+------+---------+-------------------------
1 | A | A1
2 | A | A2
3 | B | B1
4 | C | C1
5 | C | C2
6 | C | C3
....
I want to group by name, and chose the latest value for id and company. The result I expect is three column table:
id | name | company |
----+------+---------+
2 | A | A2
3 | B | B1
6 | C | C3
....
I am trying to use GROUP_BY, but don't know how to include company column:
SELECT
max(id),
name,
? # I don't know how to include company
FROM users
GROUP_BY name
Does anyone have better idea?