?
Solved

selecting across multiple tables to check permission

Posted on 2008-11-01
5
Medium Priority
?
293 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 500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, we’ll look at how to deploy ProxySQL.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

800 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