I have a query that I need to check around 20 different columns for a 0 value.
Rather than doing:
WHERE BOOK <> 0 OR ALLO <> 0 OR ...
Is there a quicker way of doing it? Something like: WHERE (BOOK,ALLO,...) <> 0
Although it doesn't run anywhere else (MySQL, SQL-Server, Postgres) and it's probably not SQL-standard, it works in Oracle:
WHERE 0 <> ANY (BOOK, ALLO, ...)
Tested in SQL-Fiddle
There is also another way that is standard and works in MySQL and Postgres, but not in Oracle:
WHERE (0, 0, ...) <> (BOOK, ALLO, ...)
And another standard way (using a Table Values Constructor) that works in Postgres and SQL-Server 2012:
WHERE 0 <> ANY (VALUES (BOOK), (ALLO), ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With