I have a field in a table which contains bitwise flags. Let\'s say for the sake of example there are three flags: 4 => read, 2 => write, 1 => execute a
4 => read, 2 => write, 1 => execute
You would need to know the possible permission components (1, 2 and 4) apriori (thus harder to maintain), but this is pretty simple and would work:
SELECT user_id, MAX(BITAND(permissions, 1)) + MAX(BITAND(permissions, 2)) + MAX(BITAND(permissions, 4)) all_perms FROM permissions GROUP BY user_id