Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 931001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:25:53+00:00 2026-05-15T20:25:53+00:00

I have three database tables – one containing units, one containing categories of those

  • 0

I have three database tables – one containing units, one containing categories of those units, and one containing user permissions.

If a user can access a category, they are allowed to access any units within the category.

I am trying to create a query that will retrieve a list of units they are allowed to access. So far I have a very awkward query that returns duplicates, and am a bit stuck, and it’s Friday afternoon, and I wanna go home!

Here are my tables:

UnitCategory

categoryid     unitid

Unit

id             name

UnitCategoryUser

unitid         userid         categoryid
               - can be null  - can be null

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:25:53+00:00Added an answer on May 15, 2026 at 8:25 pm

    I suspect that UnitCategoryUser is being used as a catch-all table for the relationships between users, categories and units – so that units are recorded as belonging to categories on records where the userid is null, and users can access units even if they don’t have access to their categories, where the categoryid is null.

    It would also be possible for units to belong to multiple categories, and for users to be recorded as being able to access the same units mutliple times – both where a user can access multiple categories (each of which can access the same unit) and where a user has been granted access to a unit without access to the category, then subsequently granted access to the category.

    The following query should return all units for a specified user:

    select distinct u.name
    from unit u 
    join unitcategory uc on u.id = uc.unitid
    join unitcategoryuser ucu on uc.category_id = ucu.categoryid
    where ucu.userid = YourUserID
    union
    select distinct u2.name
    from unit u2
    join unitcategoryuser ucu2 on u2.id = ucu2.unitid
    where ucu2.userid = YourUserID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a three database tables related for example: company( one - one) Contact(
If it matters, I'm using Firebird 2.1 database. I have three tables, one with
I have three tables in my SQL 2008 database: User, CutomerUser and SalesUser. They
I have three database tables: users emails invitations Emails are linked to users by
I have a database with three tables: user_table country_table city_table I want to write
I have a MySql database with three tables I need to combine in a
We have three developers and one tester all working against the same database. We
I have three tables in my database. News, reviews and tutorials. I would like
I have three tables in a MySQL database used in a music library application:
I have three tables STUDENT, DEPARTMENT and COURSE in a University database... STUDENT has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.