I have a table to list the transaction made by users.
mysql> select * from transaction;
+-----------+----------+------------+
| emp_id_fk | trans_id | trans_date |
+-----------+----------+------------+
| 1 | 1 | 2008-01-01 |
| 1 | 2 | 2019-01-01 |
| 1 | 3 | 2020-01-01 |
| 2 | 4 | 2020-01-10 |
| 2 | 5 | 2020-01-16 |
| 2 | 6 | 2020-01-15 |
+-----------+----------+------------+
6 rows in set (0.00 sec)
I want to know the last 2 transactions made by the users along with their transaction ID. The output should look something like this.
+-----------+----------+------------+
| emp_id_fk | trans_id | trans_date |
+-----------+----------+------------+
| 1 | 2 | 2019-01-01 |
| 1 | 3 | 2020-01-01 |
| 2 | 5 | 2020-01-16 |
| 2 | 6 | 2020-01-15 |
+-----------+----------+------------+
I've tried inner joins and group by clause but of no use. How can I generate this output?