J
John Ortt
Very quickly can someone tell me how to nest a query please?
For example if I have the following two queries can I combine them:
Part1
-------
SELECT [Query Number], [Date Raised], [Query Reason 1]
FROM qryInfoFilters
UNION SELECT [Query Number], [Date Raised], [Query Reason 2]
FROM qryInfoFilters
WHERE [Query Reason 2] Is Not Null
Part2
-------
SELECT top 10 Count(Part1.[Query Number]) AS [CountOfQuery Number],
Part1.[Query Reason 1]
FROM Part1
GROUP BY Part1.[Query Reason 1]
ORDER BY Count(Part1.[Query Number]) DESC;
I tried the following but it didn't work:
SELECT top 10 Count(Part1.[Query Number]) AS [CountOfQuery Number],
Part1.[Query Reason 1]
FROM (SELECT [Query Number], [Date Raised], [Query Reason 1]
FROM qryInfoFilters
UNION SELECT [Query Number], [Date Raised], [Query Reason 2]
FROM qryInfoFilters
WHERE [Query Reason 2] Is Not Null) as Part1
GROUP BY Part1.[Query Reason 1]
ORDER BY Count(Part1.[Query Number]) DESC;
Thanks in advance,
John
For example if I have the following two queries can I combine them:
Part1
-------
SELECT [Query Number], [Date Raised], [Query Reason 1]
FROM qryInfoFilters
UNION SELECT [Query Number], [Date Raised], [Query Reason 2]
FROM qryInfoFilters
WHERE [Query Reason 2] Is Not Null
Part2
-------
SELECT top 10 Count(Part1.[Query Number]) AS [CountOfQuery Number],
Part1.[Query Reason 1]
FROM Part1
GROUP BY Part1.[Query Reason 1]
ORDER BY Count(Part1.[Query Number]) DESC;
I tried the following but it didn't work:
SELECT top 10 Count(Part1.[Query Number]) AS [CountOfQuery Number],
Part1.[Query Reason 1]
FROM (SELECT [Query Number], [Date Raised], [Query Reason 1]
FROM qryInfoFilters
UNION SELECT [Query Number], [Date Raised], [Query Reason 2]
FROM qryInfoFilters
WHERE [Query Reason 2] Is Not Null) as Part1
GROUP BY Part1.[Query Reason 1]
ORDER BY Count(Part1.[Query Number]) DESC;
Thanks in advance,
John