'A SELECT Query Joining Data From The Same Table
The barcode values in the table below exist multiple times for certain transaction types. I'm filtering the data through a SELECT query using one specific transaction type (e.g. 'Input'), but would also like the data from another transaction type that matches with the specific barcodes being pulled through.
Data:
| Weight | Barcode | Transaction_Type | Order_No |
|:------:|:-------:|:----------------:|:--------:|
| 27.81 | 1111222 | PO | 101 |
| 27.81 | 1111222 | Input | 0 |
| 22.64 | 1111333 | PO | 102 |
| 22.64 | 1111333 | Input | 0 |
Desired Output:
| Weight | Barcode | Transaction_Type | Order_No |
|:------:|:-------:|:----------------:|:--------:|
| 27.81 | 1111222 | Input | 101 |
| 22.64 | 1111333 | Input | 102 |
Solution 1:[1]
SELECT C.WEIGHT,C.BARCODE,C.TRANSACTION_TYPE,C2.ORDERE_NO
FROM YOUR_TABLE AS C
JOIN YOUR_TABLE AS C2 ON C.BARCODE=C2.BARCODE
WHERE C.TRANSACTION_TYPE='INPUT' AND C2.TRANSACTION_TYPE='PO'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergey |
