I have a massive table where a row is defined by two ids (Tid,Bid) that looks like this:
------------------------------------------------------
| Tid | Bid | Action | Status | Value | Time |
| 1 | T | Insert | NULL | 50 | 10:11 |
| 1 | T | Update | Executed | 50 | 10:12 |
| 1 | T | Remove | Executed | 50 | 10:50 |
| 1 | S | Insert | NULL | 10 | 10:10 |
| 1 | S | Update | Executed | 10 | 10:11 |
| 2 | T | Insert | Executed | 22 | 12:20 |
| 2 | T | Remove | Executed | 22 | 12:44 |
| 3 | B | Insert | Executed | 44 | 15:21 |
| 3 | B | Update | Executed | 48 | 15:25 |
------------------------------------------------------
From this table I want to select only rows with the latest time and have the status Executed and exclude all rows with the same ids if one of those rows contained the Action Remove, so the final resoult should look like this :
------------------------------------------------------
| Tid | Bid | Action | Status | Value | Time |
| 1 | S | Update | Executed | 10 | 10:11 |
| 3 | B | Update | Executed | 48 | 15:25 |
------------------------------------------------------
Currently my solution is built with multiple nested Selects and it dosent run very fast, is there a more elegant way to solve this?