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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:46:02+00:00 2026-05-21T07:46:02+00:00

I have 2 tables as the following – CREATE TABLE IF NOT EXISTS `nl_members`

  • 0

I have 2 tables as the following –

CREATE TABLE IF NOT EXISTS `nl_members` (
  `member_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `member_email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `member_confirmation_code` varchar(35) COLLATE utf8_unicode_ci NOT NULL,
  `member_enabled` enum('Yes','No') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Yes',
  PRIMARY KEY (`member_id`),
  UNIQUE KEY `TUC_nl_members_1` (`member_email`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=58520 ;

CREATE TABLE IF NOT EXISTS `nl_member_group_xref` (
  `group_id` int(10) unsigned NOT NULL,
  `member_id` int(10) unsigned NOT NULL,
  `member_subscribed` enum('Yes','No') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Yes',
  `subscribe_date` int(10) unsigned NOT NULL DEFAULT '0',
  `unsubscribe_date` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`group_id`,`member_id`),
  KEY `nl_members_nl_member_group_xref` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


ALTER TABLE `nl_member_group_xref`
 ADD CONSTRAINT `nl_members_nl_member_group_xref` FOREIGN KEY (`member_id`) REFERENCES `nl_members` (`member_id`),
 ADD CONSTRAINT `nl_member_groups_nl_member_group_xref` FOREIGN KEY (`group_id`) REFERENCES `nl_member_groups` (`group_id`);

Both has quite some large amount of data about millions of them.

What i want is to have an efficient was of applying the MINUS on result set.

For example,

i want to get all the users from Group1 with ID: 1 MINUS all users from Group2 with ID: 2 and Group3 with ID: 3

How can i do it efficiently? with the query running as fast as possible.

Update

What i want is like this –

in members table ‘nl_members’ i keep a list of all members, who could have been associated with one or more groups.

for each group association for a member there will be a row in the ‘nl_member_group_xref’ table.

so if a member is associated with 3 groups there will be 3 entries in the member_group_xref table.

Now what i want is to get all members included in group 1 but exclude members if they also belong to group 2 and group 3.

Hope this helps.

  • 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-21T07:46:03+00:00Added an answer on May 21, 2026 at 7:46 am

    For your updated question you will need to join the two tables and group it with members_id: See below query if will display the result your looking for.

    UPDATED:

      SELECT 
             nm.*, nmgx.*
        FROM nl_members nm
       INNER JOIN nl_member_group_xref nmgx
          ON nm.member_id = nmgx.member_id
        LEFT JOIN (SELECT 
                          nmgx2.member_id
                     FROM nl_member_group_xref nmgx2
                    WHERE nmgx2.group_id <> 1) nmgx22
          ON nmgx22.member_id = nm.member_id
       WHERE nmgx22.member_id IS NULL
       GROUP BY nm.member_id;
    

    Note: I used * to get all the field name. You get specific field so the query will be more faster as it only get less results. Ex. member_id like nm.member_id

    If this is not what you looking for, just inform me then I’ll update this query as accurate as I can

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

Sidebar

Related Questions

I have the following tables: CREATE TABLE IF NOT EXISTS `Person_Categories` ( `PrsCatID` int(11)
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
I have following tables: CREATE TABLE IF NOT EXISTS stats ( date date NOT
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
I have the following tables on SQL: Mensajes IdMensaje (int) PK NOT NULL IdCliente
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have the following tables: FACULTY table CREATE TABLE FACULTY ( FACULTY_ID NUMBER(3,0), FACULTY_NAME
I have the following tables: Table A: id int v1 string v2 string Table
I have three mysql table from same database Db1. Three tables have following columns.
I have the following tables: Persons, Person_Categories and Persons_PersonCategories which is a linking table

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.