Вопрос
I'm wondering if it's possible to do a bitwise OR among MySQL query. I have a query like:
SELECT `value` FROM `table` WHERE `code`='4'
It returns an array of values, but I want a unique value with the bitwise OR of all values. Is is possible from MySQL or should I delegate to PHP?
I.e. The query above returns this list of values:
value
-----
1
5
4
2
7
8
And I want as a result the OR of these values 1 | 5 | 4 | 2 | 7 | 8 = 15
Решение
SELECT MAX(@r:=@r|value) FROM `table`, (SELECT @r:=0) x
Jim.H's suggestion is much better. Thanks!
SELECT BIT_OR(value) FROM `table`
Не связан с StackOverflow