SQL or function

Viewed 50

In SQl its common to take the SUM of all values from a column

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Can the same thing be done but instead of summing each value in an attribute, each value is "OR'd" together? This would only work if the attribute was boolean of course

2 Answers

MAX(booleancolumn) will return OR'd together. (Since TRUE > FALSE.)

Note that this will not work if null values are involved, because FALSE OR NULL evaluates to NULL.

There are two challenges here:

  1. SQL doesn't have boolean type
  2. This isn't part of any of the built-in aggregate functions.

However, some databases will allow you to define your own functions, including aggregate functions. So it is at least possible.

Related