# SQL BIT_XOR() Function

The BIT_XOR() function compares binary strings in a column, bit by bit and row by row. For each bit compared between the first two rows, it will record a "1" if the bits are different and a "0" if they are the same. It will then compare this result in the column specified from the next row. The resulting bits are then strung together to create a binary number which is then converted into base 10. Example:

SELECT color, BIT_XOR( price )

FROM monopoly_prop

WHERE color = light blue

Our original monopoly_prop table contains three properties from the light blue color group:

prop_id | name | price | group |
---|---|---|---|

4 | Oriental Ave | 100 | light blue |

5 | Vermont Ave | 100 | light blue |

6 | Connecticut Ave | 120 | light blue |

The BIT_XOR function first compares Oriental and Vermont. Finding them completely the same, the result of this comparison is zero. When Connecticut is converted to binary we are now to compare its "1111000" with the result of the previous comparison, which is "0000000". Bit by bit, with a "1" for different and "0" for the same, the result is "120".

< NOW Function SQL | Return to Index >