Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find values that do not exist in a table

Tags:

sql

oracle

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?

like image 558
John Doe Avatar asked Oct 26 '16 15:10

John Doe


People also ask

How do I find data not in another table in 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.

How do you select all records from one table that do not exist in another table in Excel?

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.

How do you check not exists in SQL?

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.


1 Answers

select column_value as missing_num
from   table (sys.odcinumberlist (123,345,555,777))
where  column_value not in (select accnt from my_table);
like image 85
mathguy Avatar answered Sep 29 '22 04:09

mathguy