Solved

selecting across multiple tables to check permission

Posted on 2008-11-01
5
282 Views
Last Modified: 2012-05-05
I have a series of tables

people
===============
id,strName,nOfficeID

office
==============
id,strName,nDistrictID

and then i have users

user
==============
id,strUsername

and then finally which districts the users can view

userdistrict
==============
id,nDistrictID,nUserID

I want to get a list of all people but only people that belong to offices which are in districts that I as a user can see. A user may see multiple districts.
0
Comment
Question by:phenixfilms
  • 2
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 22858847
you mean:
select p.strName, o.strName office_name
  from userdistrict ud
  join office o
    on o.nDistrictID = ud.nDistrictID
  join people p
    on p.nOfficeID = o.id
where id.nUserID = 1234  <<<-- the user you are querying for

Open in new window

0
 
LVL 1

Author Comment

by:phenixfilms
ID: 22858885
What about the user? I see your selecing WHERE id.nUserID.... but you've never set id to be a table or anything.

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22858920
that should have been ud.nUserID instead of id.nUserid ...
ud being the table alias of userdistrict.

I assume that you want to query for 1 single user...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now