
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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?
- Copy column values from one table into another matching IDs in MySQL
- MySQL query to copy records from one table to another with different columns
- How to copy a collection from one database to another in MongoDB?
- How to copy rows from one table to another in MySQL?
- 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?
- Copy values of one column to another using INSERT and SELECT in a single MySQL query
- Copy values from one array to another in Numpy
- MySQL query to copy IP address from varchar column to integer in the same table?
- Concatenate columns from different tables in MySQL
- MySQL statement to copy data from one table and insert into another table
- How to select different values from same column and display them in different columns with MySQL?

Advertisements