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 6997307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:16:01+00:00 2026-05-27T20:16:01+00:00

Trying to do this with a single query, but want to get a list

  • 0

Trying to do this with a single query, but want to get a list of all users who have permission to do x. This involves the users table and permissions table. But it looks like any joins I use doesnt care about the where statement (since the user will usually have another permission in the table)

SELECT DISTINCT `u`.*
FROM (`system_users` AS u)
JOIN `system_user_permissions` AS p ON `u`.`id` = `p`.`user`
WHERE `p`.`permission` != 2
AND `p`.`permission` != 3  

I have about 3900 users, I should receive about 2000 users who are not tied to either permission id 2 or 3. But still get 3900 The problem is because the user may also be tied to permission 1,5,6… they still get put in the list after it groups them together.

Any suggestions?


Updated query, still no luck though. If I output “permission” for each one I don’t get 2 or 3, the users listed still may have that permission there

SELECT DISTINCT `u`.*, `p`.`permission`
FROM (`system_users` AS u)
INNER JOIN `system_user_permissions` AS p ON `u`.`id` = `p`.`user`
WHERE `p`.`permission` NOT IN (2, 3)   

This did the trick:

SELECT * FROM system_users AS u 
        WHERE NOT EXISTS(
            SELECT 1 FROM system_user_permissions AS p
            WHERE u.id = p.user
            AND p.permission IN (2,3)
)
  • 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-27T20:16:02+00:00Added an answer on May 27, 2026 at 8:16 pm

    You want not exists:

    select
       *
    from
       system_users u
    where
       not exists (
           select 
               1 
           from 
               system_user_permissions p 
           where 
               p.id = u.user 
               and p.permission in (2,3)
       )
    

    All your original query is doing is negating any user that has only permission 2 or 3, not 1, 2, and 5 (which is what you want). A not exists will throw that user out as soon as a permission 2 or 3 is found in system_user_permissions for that user.

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

Sidebar

Related Questions

I've been trying all sorts to get this to work, I have a table
I'm trying to make a query that looks at a single table to see
I have made an application which calls the phone's contact list but i want
I am trying to write a SQL Server query but have had no luck
Basically, what I want to do is to get all children in another table
I am trying to get data from two related tables in a single query.
im trying to combine two images into a single image. unfortunately this has to
I've been trying this a couple of different ways, but it's not working for
I've been trying this a few different ways, but I'm reaching the conclusion that
I am trying this in my Form Load Event cmdCancel.Attributes.Add(onClick, document.forms[0].reset();return false;) but it

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.