I have the following two queries that I generated from the results of the union query below.
I would now like to join the two queries so that the resultant query results look like this:
Date, Line, Shift, Work Order, HeaderOP, HeaderAB, HeaderAvailHrs, SleevesCut, HeadedTubes, Printer Operator, Printer Avail Hrs, Tubes Into Press.
qryTwoNR
SELECT TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name] AS [Printer Operator ID], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press]
FROM TestHDRPRUnionqryforProdRpt INNER JOIN tbl_Employees ON TestHDRPRUnionqryforProdRpt.[Printer Operator ID] = tbl_Employees.EMPNO
GROUP BY TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press]
HAVING (((TestHDRPRUnionqryforProdRpt.MyField)="none"));
qryThreeNR
SELECT TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name] AS HeaderOP, TestHDRPRUnionqryforProdRpt.MyField AS HeaderAB, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs] AS HeaderAvailHrs, TestHDRPRUnionqryforProdRpt.[Tubes Into Press] AS SleevesCut, TestHDRPRUnionqryforProdRpt.MyField1 AS HeadedTubes
FROM TestHDRPRUnionqryforProdRpt INNER JOIN tbl_Employees ON TestHDRPRUnionqryforProdRpt.[Printer Operator ID] = tbl_Employees.EMPNO
GROUP BY TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press], TestHDRPRUnionqryforProdRpt.MyField1
HAVING (((TestHDRPRUnionqryforProdRpt.MyField)="A" Or (TestHDRPRUnionqryforProdRpt.MyField)="B"));
Union Query
SELECT [Printer Information].[Date], [Printer Information].[Line], [Printer Information].[Shift], [Printer Information].[Work Order], [Printer Information].[Printer Operator ID], "none" As MyField, [Printer Information].[Printer Avail Hrs], [Printer Information].[Tubes Into Press], "none" As MyField1
FROM [Printer Information] LEFT JOIN [Header Information]
ON [Printer Information].[Date] = [Header Information].[Date]
UNION SELECT [Header Information].[Date], [Header Information].[Line], [Header Information].[Shift], [Header Information].[Work Order], [Header Information].[Header Operator ID],[Header Information].[HeaderAB], [Header Information].[Header Avail Hrs], [Header Information].[Sleeves Cut],[Header Information].[Headed Tubes]
FROM [Header Information] RIGHT JOIN [Printer Information]
ON [Printer Information].[Date] = [Header Information].[Date];
How do I make this happen? I have tried different joins and can’t get the correct results. What am I doing wrong? Here’s my code:
SELECT qryTwoNR.Date, qryTwoNR.Line, qryTwoNR.Shift, qryTwoNR.[Work Order], qryTwoNR.[Printer Operator ID], qryTwoNR.[Printer Avail Hrs], qryTwoNR.[Tubes Into Press], qryThreeNR.HeaderOP, qryThreeNR.HeaderAB, qryThreeNR.HeaderAvailHrs, qryThreeNR.SleevesCut, qryThreeNR.HeadedTubes
FROM qryTwoNR INNER Join qryThreeNR ON qryTwoNR.Line = qryThreeNR.Line
ORDER BY qryTwoNR.Date;
This give me 800,000 records when I am looking for 210,000 records.
I would now like to join the two queries so that the resultant query results look like this:
Date, Line, Shift, Work Order, HeaderOP, HeaderAB, HeaderAvailHrs, SleevesCut, HeadedTubes, Printer Operator, Printer Avail Hrs, Tubes Into Press.
qryTwoNR
SELECT TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name] AS [Printer Operator ID], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press]
FROM TestHDRPRUnionqryforProdRpt INNER JOIN tbl_Employees ON TestHDRPRUnionqryforProdRpt.[Printer Operator ID] = tbl_Employees.EMPNO
GROUP BY TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press]
HAVING (((TestHDRPRUnionqryforProdRpt.MyField)="none"));
qryThreeNR
SELECT TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name] AS HeaderOP, TestHDRPRUnionqryforProdRpt.MyField AS HeaderAB, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs] AS HeaderAvailHrs, TestHDRPRUnionqryforProdRpt.[Tubes Into Press] AS SleevesCut, TestHDRPRUnionqryforProdRpt.MyField1 AS HeadedTubes
FROM TestHDRPRUnionqryforProdRpt INNER JOIN tbl_Employees ON TestHDRPRUnionqryforProdRpt.[Printer Operator ID] = tbl_Employees.EMPNO
GROUP BY TestHDRPRUnionqryforProdRpt.Date, TestHDRPRUnionqryforProdRpt.Line, TestHDRPRUnionqryforProdRpt.Shift, TestHDRPRUnionqryforProdRpt.[Work Order], [tbl_Employees]![Last_Name] & " " & [tbl_Employees]![First_Name], TestHDRPRUnionqryforProdRpt.MyField, TestHDRPRUnionqryforProdRpt.[Printer Avail Hrs], TestHDRPRUnionqryforProdRpt.[Tubes Into Press], TestHDRPRUnionqryforProdRpt.MyField1
HAVING (((TestHDRPRUnionqryforProdRpt.MyField)="A" Or (TestHDRPRUnionqryforProdRpt.MyField)="B"));
Union Query
SELECT [Printer Information].[Date], [Printer Information].[Line], [Printer Information].[Shift], [Printer Information].[Work Order], [Printer Information].[Printer Operator ID], "none" As MyField, [Printer Information].[Printer Avail Hrs], [Printer Information].[Tubes Into Press], "none" As MyField1
FROM [Printer Information] LEFT JOIN [Header Information]
ON [Printer Information].[Date] = [Header Information].[Date]
UNION SELECT [Header Information].[Date], [Header Information].[Line], [Header Information].[Shift], [Header Information].[Work Order], [Header Information].[Header Operator ID],[Header Information].[HeaderAB], [Header Information].[Header Avail Hrs], [Header Information].[Sleeves Cut],[Header Information].[Headed Tubes]
FROM [Header Information] RIGHT JOIN [Printer Information]
ON [Printer Information].[Date] = [Header Information].[Date];
How do I make this happen? I have tried different joins and can’t get the correct results. What am I doing wrong? Here’s my code:
SELECT qryTwoNR.Date, qryTwoNR.Line, qryTwoNR.Shift, qryTwoNR.[Work Order], qryTwoNR.[Printer Operator ID], qryTwoNR.[Printer Avail Hrs], qryTwoNR.[Tubes Into Press], qryThreeNR.HeaderOP, qryThreeNR.HeaderAB, qryThreeNR.HeaderAvailHrs, qryThreeNR.SleevesCut, qryThreeNR.HeadedTubes
FROM qryTwoNR INNER Join qryThreeNR ON qryTwoNR.Line = qryThreeNR.Line
ORDER BY qryTwoNR.Date;
This give me 800,000 records when I am looking for 210,000 records.