Skip to content
Advertisement

A reverse IN statement?

I feel like I am either overthinking this or it’s not possible but is there a way to do something like a reverse IN statement in SQL?

Instead of saying:

I want to have three columns exclude the same value like:

Is it possible to do this more efficiently with less code?

Edit: I am using a string value. Instead of nulls our DB has a space value, ”.

I used the suggested comment and changed to:

and it worked perfectly

Advertisement

Answer

Is it possible to do this more efficiently with less code?

You can shorten the expression to:

But in most databases, this will have little impact on performance. Such a construct will probably not use an index.

I cannot readily think of a way of expressing this that will use an index (in most databases). Obviously, if this is something you often need to do, you could use a function-based index.

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