I have table t1
which stores all requests. I have table t2
which stores audits related to requests made in table t1.
In order to get latest audits for every request I need to perform join on the two tables.
I am able to perform JOIN using the following query:
SELECT
t2.id, t1.name,
t2.Msg
FROM
requests t1
LEFT JOIN audits t2 ON t1.AuditId = t2.AuditId
ORDER BY t2.id DESC;
The above query is returning result as below:
id Name Msg
56895415 ABC05 Message5
56895414 ABC05 Message4
56895413 ABC05 Message3
56895303 ABC04 Message5
56895302 ABC04 Message4
56895301 ABC04 Message3
I want to modify the query such that only the last row(with highest id value)
is shown for every t1.name
In other words, my output should be as below:
id Name Msg
56895415 ABC05 Message5
56895303 ABC04 Message5