I have a parent table "A" looking like
| Main | Status | Reference |
|---|---|---|
| 1 | 0 | AA |
| 2 | 1 | AB |
| 3 | 0 | AC |
| 4 | 0 | CA |
and a child table "B" (related by 'Main') looking like
| ID | Main | C-Status | Timestamp |
|---|---|---|---|
| 1 | 1 | c | 3 |
| 2 | 1 | b | 4 |
| 3 | 2 | a | 4 |
| 4 | 2 | b | 5 |
| 5 | 2 | c | 6 |
| 6 | 3 | c | 3 |
| 7 | 4 | b | 5 |
| 8 | 4 | c | 8 |
| 9 | 4 | a | 9 |
I need to find all rows in table "A", where the latest Status in table "B" has 'C-Status' with a Value of "C" and the 'Status' in table "A" is "1"
In this example it would be 'Main' "2" (ID 5). NOT "3" (ID 6) since 'Status' is not "1"
The output I would like "A.Main", "B.C-Status", "B.Timestamp", "A.Reference"
I've been fighting with INNER JOINS and GROUP BY all my life... I just don't get it. This would be for MS-SQL 2017 if that helps, but I'm sure it's a simple thing and not essential?
