• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

selecting across multiple tables to check permission

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
phenixfilms
Asked:
phenixfilms
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
phenixfilmsAuthor Commented:
What about the user? I see your selecing WHERE id.nUserID.... but you've never set id to be a table or anything.

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now