How to get last inserted rows where a condition is satisfied table1:

esps
--------------
A
B
C
--------------


table2:

id      _name       esp
------------------------------
1       Ana        A
2       Ana        B
3       Mario      A
4       Jorge      A
5       Jorge      C
6       Ana        A
------------------------------


My query:

SELECT * FROM table2 where esp = 'A' group by _name having id = max(id);


Query result:

id      _name      esp
-----------------------------
3       Mario      A
4       Jorge      A
-----------------------------


Expected result:

id      _name      esp
-----------------------------
6       Ana        A
3       Mario      A
4       Jorge      A
-----------------------------


Any advice or sugestion will be appreciated. Mysql version 8.0.16
If you want the 'last' A:

SELECT * FROM table2
    where esp = 'A'
    ORDER BY id DESC
    LIMIT 1;


If you need something more complicated, see "groupwise-max".