Say I have a table:
ID ACCNT DESC
1 123 aaa
2 234 bbb
3 345 ccc
I have a list of account numbers 123,345,555,777.
So I can get a list that exist by
SELECT * FROM MY_TABLE WHERE ACCNT IN (...my list...)
Now I want to accomplish the opposite.
From my list I want a query to show me the account numbers that are not in the table.
So in my example I want to report that 555 and 77 does not exist in the table.
How can I write this query in Oracle SQL?
How to Select All Records from One Table That Do Not Exist in Another Table in SQL? We can get the records in one table that doesn't exist in another table by using NOT IN or NOT EXISTS with the subqueries including the other table in the subqueries.
select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. SQL> select e. select [ selecting columns] From table1 Right OUTER JOIN table2 ON(table1. select column_name from table 1 full outer join table 2 on(connection); here all the data from table 1 and table 2 will get retrieved.
NOT EXISTS is used with a subquery in the WHERE clause to check if the result of the subquery returns TRUE or FALSE. The Boolean value is then used to narrow down the rows from the outer select statement.
select column_value as missing_num
from table (sys.odcinumberlist (123,345,555,777))
where column_value not in (select accnt from my_table);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With