Row by row boolean comparison in PL/SQL?
I am trying to figure out if it is possible to do the following:
I am writing a message forum, and permissions in the forum are stored in a table 1 permission per column:
Users are associated to groups (well, the group name table [not shown] actually), and groups can be associated to multiple forums.
CREATE TABLE scc_bb_groups
(group_id NUMBER(*,0) NOT NULL,
forum_id NUMBER(*,0) NOT NULL,
PRIMARY KEY (group_id,forum_id));
Suppose a forum has two mod groups associated to it, and a given user is in both groups...
How could I collect both rows and OR them together (or however many rows there are)?
I can do this in PHP (and already have), but it would be nice to just pass in an id for a user and get all the groups they are in for a given forum and get s single row back per forum.
To clarify (with a simpler table than above):
Based on the above, the results I would like back from the query are (I will need to use an IN OUT REF CURSOR to get the results back to PHP):
grp_id forum_id view edit reply post
1 2 1 1 0 1
2 2 0 1 1 0
2 4 0 0 0 0
6 5 1 0 0 1
7 5 0 0 1 0
Would anyone be able to suggest how to write this in PL/SQL (if it can be?)
forum_id view edit reply post
2 1 1 1 1
4 0 0 0 0
5 1 0 1 1
Thanks in advance for any help!
The MAX() function will do it ...
... for example
group_id = 2
Talk about not seeing a twig for the log in my eye!
I had convinced myself that because I did it with a loop and boolean ORing in PHP, it had to be the same in PL/SQL as well. Lesson learned!
Thanks for the (simple) solution!
Click Here to Expand Forum to Full Width