Solved

selecting across multiple tables to check permission

Posted on 2008-11-01
5
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 143

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 143

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…

719 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