Nirpeksh
Nirpeksh

Reputation: 99

How to select data which is not present in table but present in where clause

I have a table A which is having data like ( '1','2','3','4') in column X.
I have some data in excel like ('1','2','3','7','8','9').
I need to run a query which returns the data which are not present in Table A but present in excel file .
In this case the result should be ('7','8','9').

Kindly help.

Upvotes: 0

Views: 2052

Answers (3)

Stanley Fernandes
Stanley Fernandes

Reputation: 432

Assume, excel_table contains id = {1,2,3,7,8,9} and table_a contains id = {1,2,3,4}

SELECT id FROM excel_table WHERE id NOT IN ( SELECT id FROM table_a );

The result of above query will be {7,8,9}

Upvotes: 2

Anuj Jain
Anuj Jain

Reputation: 31

I think you have to insert the data in excel in separate table first (LETS say tableA and EXCEL_DATA)
then just fire the statement:

 select * from EXCEL_TABLE a 
 where not exists(select 1 tableA from b where a.x = b.x)

Upvotes: 2

Srini V
Srini V

Reputation: 11365

You must load the excel data into a table. Then you can use NOT EXISTS or NOT IN or MINUS to achieve this result.

SELECT colx FROM exceltable MINUS SELECT colx FROM dbtable;

SELECT colx FROM exceltable WHERE colx NOT IN( SELECT colx FROM dbtable);

Upvotes: 1

Related Questions