Skip to content
Advertisement

Is it possible to have a nested where and and clause in oracle sql?

I’ve tried search for this and I’m not sure I’m using the correct terminology, but is it possible to have a nested WHERE AND clause?:

So the nested AND would “and (age != 18 and hair_colour != black)” so you could have:

first_name = ‘Jay’ evaluate to true

last_name = ‘McDonald’ evaluate to true

(age = 18 and hair_colour = black) only evaluate to true if both age and hair_colour are true

With the idea that only ids with both 18 and black are exclude, but not ids with just black or just 18

Advertisement

Answer

(age = 18 and hair_colour = black) only evaluate to true if both age and hair_colour are true

This already happens. You don’t even need the parentheses.

only ids with both 18 and black are exclude, but not ids with just black or just 18

You want something more like this:

But you should also look at DeMorgan’s Law, which allows us to rewrite it like this:

But let’s say you also want to require one of those to be TRUE: that is, we want an exclusive OR (XOR):

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