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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:02:41+00:00 2026-05-16T00:02:41+00:00

Can I update two identical tables with one query? TABLEA _____________________________ | id |

  • 0

Can I update two identical tables with one query?

TABLEA
_____________________________
|     id      |   value     |
|_____________|_____________| 
|      1      |      a      | 
|      2      |      b      | 
|      3      |      c      | 
|      4      |      d      | 
|      5      |      e      |    
|_____________|_____________| 

TABLEB
_____________________________
|     id      |   value     |
|_____________|_____________| 
|      1      |      a      | 
|      2      |      b      | 
|      3      |      c      | 
|      4      |      d      | 
|      5      |      e      |    
|_____________|_____________| 

I want to update both tables (SET value = 'z' WHERE id=3) at the same time.
Is this possible?

-Thanks

  • 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-16T00:02:42+00:00Added an answer on May 16, 2026 at 12:02 am

    MySQL supports multiple-table updates using the following syntax:

    UPDATE tablea, tableb
    SET    tablea.value = 'z', tableb.value = 'z'
    WHERE  (tablea.id = tableb.id) AND (tablea.id = '3');
    

    Test case:

    CREATE TABLE tablea (id int, value char(1));
    CREATE TABLE tableb (id int, value char(1));
    
    INSERT INTO tablea VALUES (1, 'a');
    INSERT INTO tablea VALUES (2, 'b');
    INSERT INTO tablea VALUES (3, 'c');
    INSERT INTO tablea VALUES (4, 'd');
    INSERT INTO tablea VALUES (5, 'e');
    
    INSERT INTO tableb VALUES (1, 'a');
    INSERT INTO tableb VALUES (2, 'b');
    INSERT INTO tableb VALUES (3, 'c');
    INSERT INTO tableb VALUES (4, 'd');
    INSERT INTO tableb VALUES (5, 'e');
    

    Result:

    SELECT * FROM tablea;
    +------+-------+
    | id   | value |
    +------+-------+
    |    1 | a     |
    |    2 | b     |
    |    3 | z     |
    |    4 | d     |
    |    5 | e     |
    +------+-------+
    5 rows in set (0.00 sec)
    
    SELECT * FROM tableb;
    +------+-------+
    | id   | value |
    +------+-------+
    |    1 | a     |
    |    2 | b     |
    |    3 | z     |
    |    4 | d     |
    |    5 | e     |
    +------+-------+
    5 rows in set (0.00 sec)
    

    UPDATE:

    If you prefer not to repeat the value you are going to set twice, you may want to use the following trick:

    UPDATE tablea, tableb, (SELECT 'z' val) d
    SET    tablea.value = d.val, tableb.value = d.val
    WHERE  (tablea.id = tableb.id) AND (tablea.id = '3');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can one transaction update two different TVar s in an atomic way? i.e. can
Possible Duplicate: How to update two tables in one statement in SQL Server 2005?
I am using two update panel..in nested way.. can i use like this and
I want to understand how I can update my GUI with a simple text
I am trying to figure out how I can update my sql query dynamically.
I have two tables almost identical: employee employee_history The second table has two additional
I have two tables. Table A and Table B. They are identical. Ever 10
The scenario I've got two tables with identical structure. TABLE [INFORMATION], [SYNC_INFORMATION] [ITEM] [nvarchar](255)
I am trying to get the diff between two nearly identical tables in postgresql.
I have two tables in my database - Category and Department which both contain

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.