I guess this is an easy and stupid question. Consider this MySQL purchase table (where p_id is autoincremented):
+---------+-------------+---------------+---------+
| p_id | item_id | user_id | count | ...
+---------+-------------+---------------+---------+
| 1 | 4 | 1 | 22|
| 2 | 4 | 2 | 1|
| 3 | 1 | 1 | 1|
| 4 | 0 | 3 | 1|
| 5 | 3 | 1 | 182|
| 6 | 0 | 4 | 1|
| 7 | 3 | 2 | 7|
| 8 | 3 | 2 | 14|
+---------+-------------+---------------+---------+
What's an appropriate way (query) to get the rows where the users whose ids are 1 and 2 have purchased the same items, and only retrieved their last purchase of those items?
The result should be something like this:
+---------+-------------+---------------+---------+
| p_id | item_id | user_id | count | ...
+---------+-------------+---------------+---------+
| 1 | 4 | 1 | 22|
| 2 | 4 | 2 | 1|
| 5 | 3 | 1 | 182|
| 8 | 3 | 2 | 14|
+---------+-------------+---------------+---------+