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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:59:16+00:00 2026-05-18T01:59:16+00:00

SELECT * FROM users WHERE username IN (john, bob, ray, sexay) Let’s say I

  • 0
SELECT
*
FROM
users
WHERE
username IN ("john", "bob", "ray", "sexay")

Let’s say I have these in my table:

ID  USERNAME
------------------
1   john
2   bob
3   jack

I want to know which of my set did not match, so I need "ray" and "sexay". Is there a pure SQL way of doing this? I know I can do this with multiple queries but I have 200 or so users and if it’s possible to do it in one query then great.

EDIT #1: A pure NOT IN is not sufficient because that would return all users that do not match my username set. I don’t need every single one, just every single username string in my given set that doesn’t match.

  • 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-18T01:59:17+00:00Added an answer on May 18, 2026 at 1:59 am

    You need to restructure your query so that your list of values are in a derived table, at which point you can use one of the standard methods to test which values from one table are not in another. The standard approaches for doing this are:

    • NOT EXISTS
    • NOT IN
    • LEFT JOIN … WHERE … IS NULL

    Here is a example of NOT EXISTS:

    SELECT T1.username
    FROM (
        SELECT 'john' AS username
        UNION ALL
        SELECT 'bob'
        UNION ALL
        SELECT 'ray'
        UNION ALL
        SELECT 'sexay'
    ) T1
    WHERE NOT EXISTS
    (
        SELECT NULL
        FROM users
        WHERE T1.username = users.username
    )
    

    Or with a join:

    SELECT T1.username
    FROM (
        SELECT 'john' AS username
        UNION ALL
        SELECT 'bob'
        UNION ALL
        SELECT 'ray'
        UNION ALL
        SELECT 'sexay'
    ) T1
    LEFT JOIN users
    ON T1.username = users.username
    WHERE users.username IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the query running on Postgres: SELECT * FROM addenda.users WHERE users.username
I have a simple query in php on oracle: $query='select u.username,u.lastname,u.firstname,c.event,c.reason from users u,
i have users table and i have posts table i want select from users
I have an SQL Statement: SELECT * FROM users WHERE username = 'bbb' OR
If I have these two rows: Users Table UserId | Username | Etc... 5
if (isset($_POST['login'])) { $query = mysql_query(" SELECT id FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'
I to do connection and have error. from u in db.aspnet_users where u.UserName.Equals(email) select
Consider these three mysql statements: select * from Users; select id, title, value from
In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights
SqlCommand command = new SqlCommand(SELECT * FROM users WHERE Username = ? AND Password

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.