PSLine2000Documentation/Queries/Processes by List.md

66 lines
2.5 KiB
Markdown

# Processes by List
Analysis generated on: 4/2/2025 10:05:48 AM
---
## SQL Statement
```sql
SELECT Process.*, Metals.Density
FROM ([Process by List] LEFT JOIN Process ON [Process by List].PN = Process.PartNumber) LEFT JOIN Metals ON Process.MetalType = Metals.PartNo
WHERE (((Process.PartNumber)<>""));
```
## Dependencies
- [[Tables/Process]]
- [[Queries/Metals]]
## Parameters
- *None*
## What it does
**SQL Code Explanation**
========================
### Overview
This SQL query retrieves data from two tables, `Process` and `Metals`, joining them based on certain conditions. The query uses subqueries to first create a temporary result set containing `Process` data and then joins it with the `Metals` table.
### Breakdown of the Query
#### Subquery: `[Process by List]`
This is an ad-hoc SQL query that creates a temporary result set (`[Process by List]`) containing data from the `Process` table. The subquery uses a `LEFT JOIN` operation to include all rows from both tables.
```sql
SELECT Process.*, Metals.Density
FROM ([Process by List] LEFT JOIN Process ON [Process by List].PN = Process.PartNumber)
```
* The subquery selects all columns (`*`) from the `Process` table and joins it with itself (noting that this might be considered redundant and inefficient).
* It then uses a `LEFT JOIN` to include rows from both tables where the join condition is met.
#### Main Query
The main query builds upon the subquery, adding another `LEFT JOIN` operation to incorporate data from the `Metals` table.
```sql
LEFT JOIN Metals ON Process.MetalType = Metals.PartNo
```
* This join operates on the `MetalType` column in the `Process` table and the `PartNo` column in the `Metals` table.
* It includes rows from both tables where there is a match in these columns.
#### Filtering Condition
The query uses an inequality condition to exclude rows with empty strings (`\u003c\u003e""`).
```sql
WHERE (((Process.PartNumber)\u003c\u003e""));
```
* This ensures that only rows with non-empty `PartNumber` values are included in the final result set.
* The double parentheses around the comparison operation allow for the use of the NOT operator.
### Final Result
The entire query is executed as a single operation, producing the following:
* A temporary result set containing data from both tables after applying the join conditions and filtering out empty strings.
* The final result includes all columns (`*`) from the `Process` table, along with the density of metals for each part number.