kentwoodjean
Technical User
While watching a great UM/MSU football game, I have also been trying to better understand and learn how to write SQL statements when joining queries. I am using the same database I got assistance on eariler this week but now I am doing this for learning purposes. I have 2 queries I would like to join into one. Following are the 2 SQL statements:
SELECT Count(tblLastUpdated.Date1) AS CountOfDate1, tblLastUpdated.Date1, tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.Date1, tblLastUpdated.[Resp Cd];
SELECT Count(tblClosedCases.[Closed Dt]) AS [CountOfClosed Dt], tblClosedCases.[Closed Dt], tblClosedCases.[Resp Cd]
FROM tblClosedCases
GROUP BY tblClosedCases.[Closed Dt], tblClosedCases.[Resp Cd];
Since the date is how I want these files sorted and the 2 date fields are not equal, I guess I cannot use a Union query. So, can an SQL statement be created that will join these 2 queries? The closed date and Date1 will need to be equal so there is only one date field. It is possible that there could be a date where there are only closes [represented by CountOfClosedDt or only receipts represented by CountOfDate1. These records should be grouped by Resp Cd. Final result would look like:
Date CountOfDate1 CountOfClosedDt RespCd
SELECT Count(tblLastUpdated.Date1) AS CountOfDate1, tblLastUpdated.Date1, tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.Date1, tblLastUpdated.[Resp Cd];
SELECT Count(tblClosedCases.[Closed Dt]) AS [CountOfClosed Dt], tblClosedCases.[Closed Dt], tblClosedCases.[Resp Cd]
FROM tblClosedCases
GROUP BY tblClosedCases.[Closed Dt], tblClosedCases.[Resp Cd];
Since the date is how I want these files sorted and the 2 date fields are not equal, I guess I cannot use a Union query. So, can an SQL statement be created that will join these 2 queries? The closed date and Date1 will need to be equal so there is only one date field. It is possible that there could be a date where there are only closes [represented by CountOfClosedDt or only receipts represented by CountOfDate1. These records should be grouped by Resp Cd. Final result would look like:
Date CountOfDate1 CountOfClosedDt RespCd