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

  • Home
  • SEARCH
  • 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 7421463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:24:48+00:00 2026-05-29T08:24:48+00:00

I have a table that stores users. Every user has an ID , a

  • 0

I have a table that stores users. Every user has an ID, a Name and an Access Level. The three possible Access Levels are Administrator, Manager and Simple User.

What I want is to conditionally select from this table based on the Access Level value. I demonstrate the logic bellow:

  1. If user is Administrator, then select all users (Administrators, Managers, Simple Users)
  2. Else if user is Manager select all Managers and all Simple Users
  3. Else if user is Simple User select only himself

Is that possible?

  • 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-29T08:24:48+00:00Added an answer on May 29, 2026 at 8:24 am

    Providing Access Level is an integer that increases with the actual access level:
    Administrator = 3
    Manager = 2
    User = 1

    Then

    SELECT * FROM USERS
    WHERE ACCESS_LEVEL <= (SELECT ACCESS_LEVEL FROM USERS WHERE ID = @ID)
    

    And just switch the less than sign to greater than if it is opposite.

    Applies to SQL-server

    EDIT: To get what you want you can use something like this:

    SELECT id,name FROM users where ID = @id
    UNION DISTINCT
    SELECT id, name from users where access_level <= 
        (select case when access_level = 1 then 0 else access_level end
        from users where id = @id)
    

    With a query like this you will select all users at your current access_level or lower.
    Only exception if your access_level is 1 (e.g. normal user), then only your own user is selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores user information. The table has a userid (identity)
I have a table that functions as an event log and stores the users
I have mysql table that has a column that stores xml as a string.
I have a table (venues) that stores all the possible venues a volunteer can
I have a table named users and each row (user) has an image. The
I have a 'stream_update' table that stores the updates users post to the groups
I have a users table, and each user has a unique user_id . Each
I have a site I am developing and it has a table that stores
I have a table that stores all the volunteers, and each volunteer will be
I have a table that stores various clients I have done work for, separated

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.