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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:12:21+00:00 2026-05-16T14:12:21+00:00

I have got 2 tables: Contacts and Users . Contacts table contains user_id which

  • 0

I have got 2 tables: Contacts and Users.

Contacts table contains user_id which are referring to id in Users table. Contacts also contain list_type column.

Contacts: user_id, list_type
Users: id, data

How can I delete entries/rows from both tables (Contacts and Users) that are referring to given list_type?

The trick is that i don’t want to delete users who belongs to other contacts list_type.

EDIT:

Example:

Users (id,data)
1    John
2    Kate
3    Alan
4    Bob

Contacts (user_id, list_type)
1    1
3    1
1    2
4    2
2    2

Now I would like to delete list_type = 2, the result should be:

Users (id,data)
1    John - still is here, because it was also referring to list_type = 1 
3    Alan

Contacts (user_id, list_type)
1    1
3    1
  • 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-16T14:12:21+00:00Added an answer on May 16, 2026 at 2:12 pm

    from what i understood, i can give you this answer..
    i guess users table has user_id field.. I gave this roughly, you make it comfortable to your code.. 😀

       select user_ids from contacts where list_type=some_type;
    
        while(resultSet.next()){
             String userid=restultSet.getString(1);
             delete from users where user_ids=userid;
        }
        delete from contacts where list_type=some_type;
    

    EDIT:

    resultSet_1 = select user_ids from contacts where list_type=some_type;  
    
    while(resultSet_1.next()){
       String userid=resultSet_1.getString(1);
       resultSet_2 = select count(user_ids) from contacts where user_id=userid group by user_ids;
       int count=resultSet_2.getInt(1);
    
       if(count==1){     //if more than 1 it means contact is in more than one list_type
           delete from users where user_ids=userid;
       }
    }
    delete from contacts where list_type=some_type;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a few tables which I am trying to join. I just
I have got a table [newsletter] in the db, which saves the email address,
I have got a table in an SQL Server 2008 R2 database. It contains
I have got two tables in SQL Server 2005: USER Table: information about user
i have a MySQL SELECT query which fetches data from 6 tables using Mysql
I have a table called 1 Main Contacts (Main), and several other tables. They
I got 4 tables, Email_Company_Contact_Ref table is the table which linked with Email, Company,
I have got a problem with two tables: CREATE TABLE IF NOT EXISTS `addresses`
I have got 5 tables of which the structures are the same. Only the
I have got tables baskets , fruits and basket_fruits (join-table: basket_id-fruit_id ). How can

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.