How to copy data from one table to another new table in MySQL?
This will do what you want:
INSERT INTO table2 (st_id,uid,changed,status,assign_status)
SELECT st_id,from_uid,now(),'Pending','Assigned'
FROM table1
If you want to include all rows from table1. Otherwise you can add a WHERE
statement to the end if you want to add only a subset of table1
.
How do I move the contents of one table to another in phpmyadmin? (same database)
Try exporting to a SQL file then change the table name and import it. The two tables have to be the same name.
Copy data into another table
If both tables are truly the same schema:
INSERT INTO newTable
SELECT * FROM oldTable
Otherwise, you'll have to specify the column names (the column list for newTable
is optional if you are specifying a value for all columns and selecting columns in the same order as newTable
's schema):
INSERT INTO newTable (col1, col2, col3)
SELECT column1, column2, column3
FROM oldTable
mysql copy complete row data from one table to another with different fields
You should use INSERT ... SELECT
instead of INSERT ... VALUES
and pass NULL
for history_id
:
INSERT INTO history_table
SELECT null, m.*
FROM master_table m
WHERE m.id = 8;
See the demo.
MySQL: Copy values from one to another table
In MySQL you can use joins to update a table with values from another table:
UPDATE table1 t1
JOIN table2 t2
ON t1.id = t2.id
SET t1.homepage = t2.homepage,
t1.name = t2.name
Copy a table to another table with different structure
Choose the columns to use and cast them to the necessary type in your select
insert into table1 (col1, col2, col3)
select cast(col1 as signed), col5, col7
from Table1_Temp
How to copy table between two models in Mysql workbench?
Your best option is probably to create a stripped down version of the model that contains the objects you want to carry over. Then open the target model and run File -> Include Model...
. Select the stripped down source model and there you go.
Related Topics
Load Data Local, How to Skip the First Line
Postgresql Get a Random Datetime/Timestamp Between Two Datetime/Timestamp
SQL Server Return the Value of Identity Column After Insert Statement
Using Left Join and Inner Join in the Same Query
Mysql: Select N Rows, But with Only Unique Values in One Column
Just Get Column Names from Hive Table
T-SQL Query:Getting Child Nodes of a Parent
A Simple Way to Sum a Result from Union in MySQL
Difference Between Fetch/For to Loop a Cursor in Pl/Sql
How to Select Using with Recursive Clause
Using MySQL, How to Sort a Column But Have 0 Come Last
Sql-How to Insert Row Without Auto Incrementing a Id Column
Type to Use for "Status" Columns in a SQL Table
Sql: When It Comes to Not in and Not Equal To, Which Is More Efficient and Why
Postgresql - Using Subqueries with Alter Sequence Expressions
Fewest Number of Buckets to Bag Elements in Bigquery
Managing Hierarchies in SQL: Mptt/Nested Sets VS Adjacency Lists VS Storing Paths