I have a query that will look for any 'Open_Tollgates' that are at a status '6' (not completed) and also the 'Department' responsible.
I ONLY want to retrieve the min(pgAct.Gate_ID) (the first Gate_Number that is not complete).
Problem is, each Tollgate (i.e. '706') is distinct because it has a specific activity ID (not displayed).
I know I need to do a subquery to filter the data. As seen below, I would essentially need just the first line (706 3 Sourcing).
What would you recommend?
Before subquery:
select pgAct.ID as Open_Tollgate, pgAct.Gate_ID as Gate_Number, secGroup.[Group] as Department
from [dbo].[Project_Gate_Activities] pgAct
join [dbo].[Activities] as Act
on pgAct.activity_order = Act.order_id
join [dbo].[Security_Group] as secGroup
on Act.group_id = secGroup.group_id
where pgAct.ID = 706
and status_id = 6
group by pgAct.id, pgAct.gate_id, secGroup.[Group]
Before subquery result set:
706 3 Sourcing
706 4 Accounting
706 4 Finance
706 4 Logistics
706 5 IT
706 6 Accounting
706 6 Finance
706 6 Purchasing
706 7 IT
706 7 Sales
706 8 Accounting