I'm having an issue with a potentially simple query I can't get working. I'm also not entirely sure on how to Google it. So here it goes.
I have 2 tables:
- TableA - Holds the main records I need to return
- TableB - Holds many records per record in TableA
All I need to do is return records from TableA that match a query such as:
SELECT Description, Type, Status
FROM TableA
WHERE Status = 2;
but with this extra bit on the end (I know the query is wrong, but hopefully it gives you a clure as to what I'm after (PSEUDO CODE):
SELECT ID, Description, Type, Status
FROM TableA
JOIN TableB ON TableB.ID = TableA.ID
WHERE Status = 2
AND (MIN(TableB.StatusChanged) > DATEADD(minute, -15, GETDATE()))
AND TableB.Status < 5;
So essentially I want to return all records from TableA as long as they have a status of 2 in TableA, and the earliest record in TableB is at least 15 minutes old, and has a status value less than 5.
Hopefully I have explained it in a way you can understand what I'm trying to accomplish.