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

  • Home
  • SEARCH
  • 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 6533203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:05:47+00:00 2026-05-25T10:05:47+00:00

Definition of both tables (it’s just an example, I can’t merge tables, no): CREATE

  • 0

Definition of both tables (it’s just an example, I can’t merge tables, no):

CREATE TABLE `MyTable`(
  `id` int NOT NULL,
  `a` varchar(10) NOT NULL, 
  `b`  varchar(10) NOT NULL,
  `state` tinyint NOT NULL,
  PRIMARY KEY (`id`)
);

Goal: Update MyTable1 records that don’t share any value with “a” OR “b” from MyTable2.

My solution:

update MyTable1 as t1 
  inner join MyTable2 as t2 on (t1.a != t2.a and t1.b != t2.b) 
set t1.state=3;

I’m basically joining tables where no columns match, so that I can update the state of such records.

My problem: This is slow. It took 6 seconds with 5000 entries in MyTable1 and 3000 entries in MyTable2.

Question: Can it be any faster (if your solution goes a lot faster, I’ll take it too ;)?

EDIT: My “solution” actually doesn’t work at all.

  • 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-25T10:05:48+00:00Added an answer on May 25, 2026 at 10:05 am

    Your join might find a ton of matches per row. That can make a join really expensive. Try a not exists instead:

    update  MyTable1 as t1
    set     t1.state = 3
    where   not exists
            (
            select  *
            from    MyTable2 as t2 
            where   t1.a = t2.a 
                    or t1.b = t2.b
            )
    

    or even a double subquery:

    where   not exists
            (
            select  *
            from    MyTable2 as t2 
            where   t1.a = t2.a 
            )
            and not exists
            (
            select  *
            from    MyTable2 as t2 
            where   t1.b = t2.b
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with identical definition. T1: Name VARCHAR(50) Qty INT T2: Name
I am trying the following SQL statement: create table sample ( id int not
let's said table A create with definition keyword varchar(255) collate latin1_general_cs with index create
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
I've got two Java projects, both generate Java classes based on a schema definition,
Why definition of std::function<>::operator() in the C++ standard is: R operator()(ArgTypes...) const; and not
The definition of AudioBufferList looks weird to me… i guess my C is not
as for the definition of Person: public class Person { private int id; private
I have 2 tables: Ones Twos Both have a has_many relationship towards each other
I'm using packages subfigure and float to create figures and tables that I want

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.