I need an SQL code to compare data that doesn't exist in one table with respect to another table that holds the set of unique expected data.
I have tried using EXIST and NOT EXIST operators.
The EXIST operator will display all data in the second table. The NOT EXIST operator will not display any results.
The code looks something like
SELECT *
FROM st
WHERE EXISTS
(SELECT data FROM udt WHERE st.data <> udt.data)
This is my unique data table (udt) example:
+------+
| data |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
+------+
This is my second table (st) example:
+------+------+
| name | data |
+------+------+
| AZ | 1 |
| AZ | 3 |
| BY | 2 |
| BY | 4 |
| CX | 1 |
| CX | 4 |
| DW | 2 |
| DW | 3 |
+------+------+
I would like to have a code that will display the name and the code that don't exist in the second table. That is:
+------+------+
| name | data |
+------+------+
| AZ | 2 |
| AZ | 4 |
+------+------+
and so on
For one, will this be possible? If it is possible, what code syntax can I apply? I get why EXIST and NOT EXIST will not display the data, but is there any way I can get the required results?