chris chris - 5 months ago 9
SQL Question

How to aggregate boolean column

How can I aggregate some tuples like this

COL_1 | COL_2 | COL_3 | COL_4
val | T | F | F
val | F | T | F


with the OR function and return the following table?

COL_1 | COL_2 | COL_3 | COL_4
val | T | T | F

Answer

Simply do a GROUP BY, use MAX() to return T if available, else F.

select col_1, max(col_2), max(col_3), max(col_4)
from tablename
group by col_1