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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:17:43+00:00 2026-06-16T00:17:43+00:00

Using MySQL, I’d like to list all users that don’t have the document liaison.

  • 0

Using MySQL, I’d like to list all users that don’t have the document “liaison”. It could means Users that does not have any document at all, or users that have documents, but not “liaison” in these ones.

How can I do using MySQL Query ? I can’t make it work!

Here’s the (simple) model

Users (id, name)
Documents (id, user_id, name, path)
  • 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-06-16T00:17:44+00:00Added an answer on June 16, 2026 at 12:17 am

    The NOT EXISTS is a workable solution. As an alternative, sometimes, with large sets, an “anti JOIN” operation can give better performance:

    SELECT u.*
      FROM Users u
      LEFT
      JOIN (SELECT d.user_id
              FROM Documents d
             WHERE d.name = 'liaison'
           ) l
        ON l.user_id = u.id
     WHERE l.user_id IS NULL
    

    The inline view aliased as l returns us a list of user_id that have document named ‘liaison’; that result set gets outer joined to the Users table, and then we exclude any rows where we found a match (the test of l.user_id IS NULL).

    This returns a resultset equivalent to your query with the NOT EXISTS predicate.

    Another alternative is to use a query with a NOT IN predicate. Note that we need to guarantee that the subquery does not return a NULL, so the general approach is to include an IS NOT NULL predicate on the column being returned by the subquery.

    SELECT u.*
      FROM Users u
     WHERE u.id NOT IN 
           ( SELECT d.user_id 
               FROM Documents d
              WHERE d.user_id IS NOT NULL
                AND d.name = 'liaison'
           )
    

    I’d write the NOT EXISTS query like this:

    SELECT u.*
      FROM Users u
     WHERE NOT EXISTS 
           ( SELECT 1
               FROM Documents d
              WHERE d.name = 'liaison'
                AND d.user_id = u.id
           )
    

    My personal preference is to use a literal 1 in the SELECT list of that correlated subquery; it reminds me that the query is just looking for the existence of 1 row.)

    Again, I usually find that the “anti-join” pattern gives the best performance with large sets. (You’d need to look at the EXPLAIN output for each statement, and measure the performance of each to determine which will work best in your situation.)

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

Sidebar

Related Questions

Using MySQL, I have a simple table that logs the IP Address that users
(Using MySQL and PHP) I have a search form that will allow my users
Using MySQL, i have a current timestamp that looks like this: 2011-11-01 10:34:24 Is
Using MySQL, I have a number of queries that look like: SELECT * FROM
Using MySQL, i'm selecting a list of songs in spanish that i would like
Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
I m using mysql. in one field i have inserted data like string1::string2 two
Using MySQL I have table of users, a table of matches (Updated with the
Using MySQL, I want to return a list of parents, from a table that
Using MySQL I need to have a list (possibly long list) of x,y coordinates.

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.