
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copy from one column to another (different tables same database) in MySQL?
To copy from one column to another, you can use INSERT INTO SELECT statement.
Let us first create a table −
mysql> create table DemoTable1 (PlayerScore int); Query OK, 0 rows affected (0.46 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values(98); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1 values(81); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1 values(76); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values(88); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
This will produce the following output -
+-------------+ | PlayerScore | +-------------+ | 98 | | 81 | | 76 | | 88 | +-------------+ 4 rows in set (0.00 sec)
Here is the query to create a second table −
mysql> create table DemoTable2 (Marks int); Query OK, 0 rows affected (0.47 sec)
Here is the query to copy from one column to another (different tables same database) MySQL −
mysql> insert into DemoTable2(Marks) select PlayerScore from DemoTable1; Query OK, 4 rows affected (0.19 sec) Records: 4 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select *from DemoTable2;
This will produce the following output -
+-------+ | Marks | +-------+ | 98 | | 81 | | 76 | | 88 | +-------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- How to copy a table from one MySQL database to another?
- How to copy tables or databases from one MySQL server to another MySQL server?
- MySQL query to copy records from one table to another with different columns
- Copy column values from one table into another matching IDs in MySQL
- How to copy a collection from one database to another in MongoDB?
- How to copy rows from one table to another in MySQL?
- Copy values from one array to another in Numpy
- Insert from one table with different structure to another in MySQL?
- Simplest way to copy data from one table to another new table in MySQL?
- How to copy data from one field to another on every row in MySQL?
- MySQL statement to copy data from one table and insert into another table
- Concatenate columns from different tables in MySQL
- Copy all the elements from one set to another in Java
- How to copy files from one server to another using Python?
- How to copy files from one folder to another using Python?
Advertisements