-3

I have a table as below. Need a Query to select the Last activity of the User. (There should not be multiple listing for same user, Single user single row)

Click here for Table

+----------------+---------+--------------------+-----------------+------------+
|      Date      | BOT_ID  |      Process       |  LastModified   |   Status   |
+----------------+---------+--------------------+-----------------+------------+
| 17/09/26 00:00 | User 1  | Interaction record | 9/19/2017 10:50 | In Process |
| 17/09/26 00:00 | User 2  | Single Assessed    | 9/26/2017 12:00 | In process |
| 17/09/26 00:00 | User 3  | Interaction record | 9/26/2017 11:35 | Completed  |
| 17/09/26 00:00 | User 4  | Metering           | 9/26/2017 11:50 | In proce   |
| 17/09/26 00:00 | User 1  | Move In            | 9/26/2017 11:50 | In process |
| 17/09/26 00:00 | User 4  | Interaction record | 9/26/2017 11:58 | Completed  |
| 17/09/26 00:00 | User 5  | Direct Debit       | 9/26/2017 11:10 | Completed  |
| 17/09/26 00:00 | User 17 | latest             | 9/26/2017 0:15  | In Process |
+----------------+---------+--------------------+-----------------+------------+
etsa
  • 5,020
  • 1
  • 7
  • 18

2 Answers2

1

You can try this query. The subselect calculate max(lastmodified) for each user, using GROUP BY. The result is joined to main table using BOT_ID and the calculated date with lastmodified date. If a user has two same date lastmodified, both the rows will be returned:

SELECT A.* 
FROM YOURTABLE A
INNER JOIN (SELECT BOT_ID, MAX(LASTMODIFIED) AS LAST_ACTIVITY 
            FROM YOURTABLE 
            GROUP BY BOT_ID) B ON A.BOT_ID=B.BOT_ID AND A.LASTMODIFIED = B.LAST_ACTIVITY
etsa
  • 5,020
  • 1
  • 7
  • 18
0

You can use:

Select Max([Last Modified]) As [Last Activity] 
From YourTable 
Where BOT_ID = "User 1" 

To list all:

Select BOT_ID, Max([Last Modified]) As [Last Activity] 
From YourTable 
Group By BOT_ID
Gustav
  • 53,498
  • 7
  • 29
  • 55