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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:07:23+00:00 2026-06-11T05:07:23+00:00

i use this code update contracts a, contracts_history b set a.name_surname=b.name_surname My table has

  • 0

i use this code

update 
contracts a, 
contracts_history b 
set 
a.name_surname=b.name_surname 

My table has 64 columns and I am looking for a solution to copy all data with out having to specify column names – along these lines:

 $sql = "INSERT INTO `contracts_history` 
         SELECT * FROM `contracts` WHERE id='$contract_id'";
  • 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-11T05:07:25+00:00Added an answer on June 11, 2026 at 5:07 am

    You can use the insert into select... syntax as long as your tables are exactly the same number of fields with matching datatypes – otherwise you will have to use column names to specify what you want to copy.

    I just ran the following as an example for you to show you the syntax:

    mysql> use test
    Database changed
    mysql> show tables;
    Empty set (0.00 sec)
    
    mysql> create table test1 (id int(2), varry varchar(3));
    Query OK, 0 rows affected (0.08 sec)
    
    mysql> create table test2 (id int(2), barry varchar(3));
    Query OK, 0 rows affected (0.05 sec)
    
    mysql> insert into test2 values(1,'aaa');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from test1;
    Empty set (0.00 sec)
    
    mysql> insert into test1 (select * from test2);
    Query OK, 1 row affected (0.06 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> select * from test1;
    +------+-------+
    | id   | varry |
    +------+-------+
    |    1 | aaa   |
    +------+-------+
    1 row in set (0.00 sec)
    
    mysql> alter table test2 add column third int(1);
    Query OK, 1 row affected (0.06 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    mysql> update test2 set barry='ccc';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> insert into test1 (select * from test2);
    ERROR 1136 (21S01): Column count doesn't match value count at row 1
    mysql>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to update data in database table. Can reuse same code
I try to update my profile image and use this code: $connection->post('account/update_profile_image', array('image' =>
I want update table contracts by values in contracts_history table where both of id
I use this code : MethodInvoker TileLoadCompleteMethodInvoker = delegate() { CleanStatusLabelTimer.Enabled = true; MemoryTextBox.Text
i use this code in my app. just found is not correct when compare
I use this code to connect to SQL Server 2012, but it does not
I use this code to select password field from the sql server 2012 db,
I use this code , to log $_SERVER['REMOTE_ADDR']; to my small db my issue
I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically
I use this code to process a date string coming in from a json

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.