Mysql group by two columns and pick the maximum value of third column
问题 I have a table that has user_id, item_id and interaction_type as columns. interaction_type could be 0, 1,2,3,4 or 5. However, for some user_id and item_id pairs, we might have multiple interaction_types. For example, we might have: user_id item_id interaction_type 2 3 1 2 3 0 2 3 5 4 1 0 5 4 4 5 4 2 What I want is to only keep the maximum interaction_type if there are multiples. So I want this: user_id item_id interaction_type 2 3 5 4 1 0 5 4 4 Here is the query I wrote for this purpose: