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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:01:05+00:00 2026-06-13T08:01:05+00:00

I need to select records which exist in users table but don’t exist in

  • 0

I need to select records which exist in users table but don’t exist in tables groups_members, groups_members_unapproved and groups_invitations.

$_POST[‘msg_id’] contains multiple user IDs and I don’t know how to use implode statement in 3 subqueries, so I replaced it with ??? – question marks.

Thanks.

$result = mysql_query("SELECT id FROM users
WHERE id IN (". implode(', ', $_POST['msg_id']).")
AND id NOT IN (SELECT memberid FROM groups_members where memberid='???' and groupid='$cid')
AND id NOT IN (SELECT memberid FROM groups_members_unapproved where memberid='???' and groupid='$cid')
AND id NOT IN (SELECT invited FROM groups_invitations where invited = '???' and groupid='$cid')",$gb1) or die('Error');
  • 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-13T08:01:06+00:00Added an answer on June 13, 2026 at 8:01 am

    What you are likely looking to do is a LEFT OUTER JOIN like this

    SELECT id FROM users AS u
    LEFT OUTER JOIN groups_members AS gm ON u.id = gm.memberid
    LEFT OUTER JOIN groups_members_unapproved AS gmu ON u.id = gmu.memberid
    LEFT OUTER JOIN groups_invitations AS gi ON u.id = gi.invited
    WHERE
    id IN (<your implode here>)
    AND gm.memberid IS NULL
    AND gmu.memberid IS NULL
    AND gi.invited IS NULL
    AND gm.groupid <> <your group id>
    AND gmu.groupid <> <your group id>
    AND gi.groupid <> <your group id>
    

    The thought here being that the outer join will return records across all joined tables even when there are not matching id’s, but that the * IS NULL lines in the where clause will limit those records to only the cases where there are not matching member id’s between the user table and any of the other tables.

    I wasn’t quite sure what value the groupid was bringing in your query. I would think that if you are concerned with identifying records at the user level that it would be an unnecessary field to filter on.

    This should be a more efficient query than using subselects, so long as all your ID fields are indexed. Of course if this is a query which you expect to execute frequently, you may want to consider a schema change to get an even more optimized query.

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

Sidebar

Related Questions

I need to select multiple records I use SELECT * FROM `table` WHERE `ID`
I need to select only 20 records from the table and than add pagination
Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
I have an sql query in which I need to select the records from
I need to select records where a column value is LIKE any of the
I need some help with SQL Query. I am trying to select all records
Suppose i have 1kk records in my database. Now i need to select some
I have a table with a datetime record. I need to select the record
how can i express in xpath a) need select elements which contains specified keyword.
consider the following example. I have to select all the records from table1 which

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.