3.4 KiB
Sort by Machine
Analysis generated on: 4/2/2025 10:11:37 AM
SQL Statement
SELECT Machines.MachineName, Machines.PartNumber, Machines.CycleTime, Machines.Prime, Machines.Tool, [Util Make Duplicate Revision Remover 2].prt, [Util Make Duplicate Revision Remover 2].Rev INTO [Sorted By Machines 1]
FROM [Util Make Duplicate Revision Remover 2] LEFT JOIN Machines ON [Util Make Duplicate Revision Remover 2].PN = Machines.PartNumber
GROUP BY Machines.MachineName, Machines.PartNumber, Machines.CycleTime, Machines.Prime, Machines.Tool, [Util Make Duplicate Revision Remover 2].prt, [Util Make Duplicate Revision Remover 2].Rev
HAVING (((Machines.MachineName)=[Forms]![Sorted by Machine]![Machine Name]))
ORDER BY Machines.PartNumber, [Util Make Duplicate Revision Remover 2].prt;
Dependencies
Parameters
- [Forms]![Sorted by Machine]![Machine Name] (Empty)
What it does
SQL Code Description
Overview
This SQL code retrieves data from two tables: [Util Make Duplicate Revision Remover 2]
and Machines
. The query joins these tables on a common column (PartNumber
) and filters the results based on specific conditions.
SQL Breakdown
SELECT Clause
SELECT
Machines.MachineName,
Machines.PartNumber,
Machines.CycleTime,
Machines.Prime,
Machines.Tool,
[Util Make Duplicate Revision Remover 2].prt,
[Util Make Duplicate Revision Remover 2].Rev INTO [Sorted By Machines 1]
This selects the following columns:
MachineName
from theMachines
tablePartNumber
,CycleTime
,Prime
, andTool
columns from theMachines
tableprt
(a column with a name containing " prt") from the[Util Make Duplicate Revision Remover 2]
tableRev
(a column with a name containing " Rev") from the[Util Make Duplicate Revision Remover 2]
table
The INTO [Sorted By Machines 1]
clause creates an alias for the result set.
JOIN Clause
FROM [Util Make Duplicate Revision Remover 2]
LEFT JOIN Machines ON [Util Make Duplicate Revision Remover 2].PN = Machines.PartNumber
This joins the [Util Make Duplicate Revision Remover 2]
table with the Machines
table on the common column PartNumber
. The LEFT JOIN
ensures that all records from the left table ([Util Make Duplicate Revision Remover 2]
) are included in the result set, even if there is no match in the right table (Machines
).
GROUP BY Clause
GROUP BY
Machines.MachineName,
Machines.PartNumber,
Machines.CycleTime,
Machines.Prime,
Machines.Tool,
[Util Make Duplicate Revision Remover 2].prt,
[Util Make Duplicate Revision Remover 2].Rev
This groups the result set by all selected columns.
HAVING Clause
HAVING (((Machines.MachineName)=[Forms]![Sorted by Machine]![Machine Name]))
This filters the grouped result set to include only rows where the MachineName
column in the Machines
table matches a specific value from the [Forms]!...
field. The exact value is not specified in this code snippet, but it appears to be a lookup value provided by a form control.
ORDER BY Clause
ORDER BY
Machines.PartNumber,
[Util Make Duplicate Revision Remover 2].prt;
This sorts the final result set by the PartNumber
column from the Machines
table and then by the prt
column from the [Util Make Duplicate Revision Remover 2]
table.