I'm trying to save some time and effort by combining some frequent queries into one. Basically, I need to see the customers which have purchased in FYxx and have not purchased in FYxx+1 AND FYxx+2. To do this I need to create 4 queries:
[FY06 TCC] gives me the customers from FYxx
[FY07 TCC] gives me the customers from FYxx+1
[FY08 TCC] gives me the customers from FYxx+2
The real work is done in Query 4 which finds all the customers in [FY06 TCC] that DO NOT exist in [FY07 TCC] AND [FY08 TCC]
The problem I'm having is every example I find about subqueries is either an uncorrelated subquery, where I need to compare against a single result, or a correlated subquery, where I compare a single result against each line in the main query. I know the correlated sunquery is the way to go, but I can't get past the rrror messages telling me "At most one record can be returned by this subquery". I have even tried to keep it simple and just compare against [FY07 TCC].
Any help would be greatly appreciated.
[FY06 TCC] gives me the customers from FYxx
Code:
SELECT [Main Invoice Data].[EndUser OCN:]
FROM [Main Invoice Data]
WHERE ((([Main Invoice Data].[Invoice Fiscal Year:])=2006))
GROUP BY [Main Invoice Data].[EndUser OCN:]
ORDER BY [Main Invoice Data].[EndUser OCN:];
Code:
SELECT [Main Invoice Data].[EndUser OCN:]
FROM [Main Invoice Data]
WHERE ((([Main Invoice Data].[Invoice Fiscal Year:])=2007))
GROUP BY [Main Invoice Data].[EndUser OCN:]
ORDER BY [Main Invoice Data].[EndUser OCN:];
Code:
SELECT [Main Invoice Data].[EndUser OCN:]
FROM [Main Invoice Data]
WHERE ((([Main Invoice Data].[Invoice Fiscal Year:])=2008))
GROUP BY [Main Invoice Data].[EndUser OCN:]
ORDER BY [Main Invoice Data].[EndUser OCN:];
Code:
SELECT [FY06 TCC].[EndUser OCN:]
FROM ([FY06 NCC] LEFT JOIN [FY07 TCC] ON [FY06 NCC].[EndUser OCN:] = [FY07 TCC].[EndUser OCN:]) LEFT JOIN [FY08 TCC] ON [FY06 NCC].[EndUser OCN:] = [FY08 TCC].[EndUser OCN:]
WHERE ((([FY07 TCC].[EndUser OCN:]) Is Null) AND (([FY08 TCC].[EndUser OCN:]) Is Null))
GROUP BY [FY06 TCC].[EndUser OCN:]
ORDER BY [FY06 TCC].[EndUser OCN:];
Code:
SELECT [FY06 NCC].[EndUser OCN:]
FROM [FY06 NCC]
WHERE ((([FY06 NCC].[EndUser OCN:])<>(SELECT [Main Invoice Data].[EndUser OCN:]
FROM [Main Invoice Data]
WHERE ((([Main Invoice Data].[Invoice Fiscal Year:])=2007)))))
ORDER BY [FY06 NCC].[EndUser OCN:];