Skip to content
Advertisement

SQL (Oracle) – Select where record does not exist or another column in the 2nd table is true

I am trying to write a sql statement that looks at tables similar to the example above. What I need for results is a record that exists in the applications table that has an application type of education and a status type of approved but does not have a record in the assignments table. However if a record exists in the assignments table then the Inactive column has to be 1. Below is the sql I’ve been working with

I also tried the below sql but then I get John Smith, Jane Doe, and Sara Jane.

The records I’d expect to get back would be John Smith and Sara Jane. Currently I am getting those 2 records and Jane Doe which I do not want in my results set.

Advertisement

Answer

I am thinking not exists:

If you want to express this using left join, the logic is:

Here is a db<>fiddle.

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