I have two tables named StationUtilization and Process. Both tables have columns TestStart and TestDateTime respectively and should have similar records.
However, there are some missing records in TestStart column of StationUtilization table that needs to be added. How can I compare these two columns to get the missing values?
Example:
StationUtilization Table
ID | TestStart | ….. |
---|---|---|
1 | 2021-01-01 22:42:23.000 | |
2 | 2021-01-02 22:42:23.000 | |
3 | 2021-01-05 22:42:23.000 |
Process Table:
ID | TestDateTime | ….. |
---|---|---|
1 | 2021-01-01 22:42:23.000 | |
2 | 2021-01-02 22:42:23.000 | |
3 | 2021-01-03 22:42:23.000 | |
4 | 2021-01-04 22:42:23.000 | |
5 | 2021-01-05 22:42:23.000 |
Expected output after comparison:
ID | TestDateTime | ….. |
---|---|---|
3 | 2021-01-03 22:42:23.000 | |
4 | 2021-01-04 22:42:23.000 |
Advertisement
Answer
x
SELECT * FROM StationUtilization
LEFT JOIN Process
ON Process.TestDateTime = StationUtilization.TestStart
WHERE PROCESS.ID is null