Skip to content
Advertisement

Oracle SQL Subquery – Usage of NOT EXISTS

I used a query to find a list of Primary Keys. One Primary key per each ForiegnKey in a table by using below query.

Let us say this is the result : 1,4,5

NOw I have another table – Table B that has list of all Primary keys. It has 1,2,3,6,7,8,9

I want a write a query using the above query So that I get a subset of the original query(above) that does not exist in Table B. I want 4 and 5 back with the new query.

Advertisement

Answer

Use a having clause:

You should also be able to express this as not exists:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement