View Single Post
Old 07-27-2004, 11:17 AM   #1 (permalink)
moskie_work
Upright
 
[SQL] Joining a user permissions table

I'm having trouble figuring this query out, maybe you guys can help me.

I'm adding a user administration module to an existing system, where an administrator can view and modify users' access rights to particular sections.

We got three tables: Users, Sections, and UserSectionRights. UserSectionRights has a foriegn key to User, a Foreign key to userSectionRights, and an integer representing the access level for that user/section combination.

For this admin module, i would like to get a table that looks like this:
Code:
	  |  Section 1 Access Level  |  Section 2 Access Level  |  ... <more columns for however many sections>
-----------------------------------------------------------------------------------------------------------------------
UserName1 |			     |                          |
UserName2 |			     |                          |
UserName3 |			     |                          |
UserName4 |			     |                          |
UserName5 |			     |                          |
...etc...

If I use joins, i end up getting a line for each user/section combination, as opposed to having all the combinations together. That's gonna be what I'll end up dealing with, if I can't figure this out.

I don't think subqueries are an option, because i'd like this to be dynamic, so that this query will still work when new sections are added. As I see it, i'd have to hard-code a subquery for each section.

Any ideas? hopefully i've explained things clearly! :-)
moskie_work is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76