chris chris - 1 year ago 75
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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download