Filibuster
New Member
- Joined
- Oct 17, 2013
- Messages
- 7
I am trying to combine the output of two SELECT TOP queries into a single query output result. I thought a simple UNION query would do the trick, but ran into problems associated with the ORDER BY statement with the UNION query. The only difference between the two SELECT TOP queries is the parameter of the HAVING criteria. I have tried several workarounds but cannot seem to make the UNION (or any other approach work). Here is the SQL of the two SELECT TOP queries:
Code:
SELECT TOP 25 tblTasks.Task, tblTasks.Task_Status, tblTasks.Award_Date, tblTasks.End_Date, Sum(tblPRs.Ceiling_Final) AS SumOfCeiling_Final, tblTasks.Program, tblTasks.Prime, tblClient.Org_Top
FROM (tblTasks INNER JOIN tblClient ON tblTasks.Task_ID = tblClient.Task_ID) INNER JOIN tblPRs ON tblTasks.Task_ID = tblPRs.Task_ID
GROUP BY tblTasks.Task, tblTasks.Task_Status, tblTasks.Award_Date, tblTasks.End_Date, tblTasks.Program, tblTasks.Prime, tblClient.Org_Top
HAVING (((tblTasks.Task_Status)="open"))
ORDER BY Sum(tblPRs.Ceiling_Final) DESC;
Code:
SELECT TOP 25 tblTasks.Task, tblTasks.Task_Status, tblTasks.Award_Date, tblTasks.End_Date, Sum(tblPRs.Ceiling_Final) AS SumOfCeiling_Final, tblTasks.Program, tblTasks.Prime, tblClient.Org_Top
FROM (tblTasks INNER JOIN tblClient ON tblTasks.Task_ID = tblClient.Task_ID) INNER JOIN tblPRs ON tblTasks.Task_ID = tblPRs.Task_ID
GROUP BY tblTasks.Task, tblTasks.Task_Status, tblTasks.Award_Date, tblTasks.End_Date, tblTasks.Program, tblTasks.Prime, tblClient.Org_Top
HAVING (((tblTasks.Task_Status)="pending"))
ORDER BY Sum(tblPRs.Ceiling_Final) DESC;