PSLine2000Documentation/Queries/AddnlQ1.md

2.8 KiB

AddnlQ1

Analysis generated on: 4/2/2025 9:56:48 AM

SQL Statement

SELECT DISTINCTROW AddnlProc.PartNumber, AddnlProc.OPCode, AddnlProc.ID, AddnlProc.Generated, AddnlProc.Description, AddnlProc.WC1, AddnlProc.WC2, AddnlProc.WC3, AddnlProc.WC4, AddnlProc.Machine, AddnlProc.CycleTime, AddnlProc.RunStd, Labor.LaborRate
FROM AddnlProc INNER JOIN Labor ON AddnlProc.WC2 = Labor.WC2
ORDER BY AddnlProc.PartNumber, AddnlProc.OPCode, AddnlProc.ID;

Dependencies

Parameters

  • None

What it does

SQL Query Description

Overview

This SQL query retrieves a distinct set of rows from two tables: AddnlProc and Labor. The query joins the two tables on a common column (WC2) and returns various columns, grouped by specific criteria.

Query Breakdown

SELECT Clause

The query starts with the SELECT DISTINCTROW statement, which specifies that only distinct rows should be returned. However, this clause seems redundant in combination with DISTINCTROW, as DISTINCTROW already ensures that each row is unique based on its values. For simplicity and consistency, it's recommended to use just DISTINCT.

The query selects the following columns from both tables:

  • AddnlProc.PartNumber
  • AddnlProc.OPCode
  • AddnlProc.ID
  • AddnlProc.Generated
  • AddnlProc.Description
  • AddnlProc.WC1, AddnlProc.WC2, and AddnlProc.WC3 columns from the AddnlProc table
  • Labor.LaborRate

INNER JOIN Clause

The query joins the AddnlProc table with the Labor table on a common column (WC2). This creates a new table that combines rows from both tables where the value in WC2 is the same.

ORDER BY Clause

Finally, the query sorts the resulting combined table by the following columns:

  • AddnlProc.PartNumber
  • AddnlProc.OPCode
  • AddnlProc.ID

This ensures that the results are presented in a consistent order.

Potential Improvements

  1. Use DISTINCT instead of DISTINCTROW: While DISTINCTROW provides some benefits, using DISTINCT alone is sufficient and more straightforward.
  2. Consider indexing: If the join operation frequently uses the same columns for sorting (as in this query), creating an index on these columns could improve performance.

Example Output

PartNumber OPCode ID Generated Description WC1 WC2 WC3 Machine CycleTime RunStd LaborRate

Assuming the WC2 value in each row is unique, this query would return one row per combination of values from these columns. If there are duplicate rows for a specific set of values (e.g., same part number and operation code), only one will be included in the results.