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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:35:40+00:00 2026-06-07T17:35:40+00:00

I have some data pollution in a table that I’m having a hard time

  • 0

I have some data pollution in a table that I’m having a hard time removing… I’ve fixed the cause of the pollution so it won’t happen again, but there are a bunch of records I now need to delete and I’m having a hard time figuring out how.

The nature of the problem is as follows.

I have a table that has userIds and groupIds. It is valid for a user to exist in multiple groups, so this isn’t something I can solve with a unique association.

In my case, let’s say groups 4 and 5 are mutually exclusive (meaning a user can’t belong to both).

I need to run a delete on the user_groups table where I can say (in english):
Delete this row if the userID = X and the group ID = 4 IF there is also a row where the userID = X and the groupID = 5.

I don’t want to delete ALL the rows where the groupID = 4, only those that apply to users who also have a row containing groupID = 5.

All help greatly appreciated.

  • 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-07T17:35:42+00:00Added an answer on June 7, 2026 at 5:35 pm

    This will delete all the users in group 4 that have a duplicate in group 5.

    DELETE FROM user_groups AS G1 
    WHERE G1.groupID=4 
      AND G1.userID IN (SELECT G2.userID FROM user_groups 
                        WHERE G2.userID=G1.userID AND G2.GroupID=5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that won't printf.... echo works, but not printf There is
I have some data- attributes that I put into a table row tag. When
I have some data that's formatted as follows: dtau E_av variance N_sims Time 0.001
I have some data in a table that looks like this: Adam $50 Evan
I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in
I have some data that I would like to visualize. Each byte of the
Have some data in a sybase image type column that I want to use
I have some data analysis code that processes an input file and outputs HTML
I have some data in this mysql table, but it is not showing anything
I have some data that lends itself to representation as a value and a

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.