ItSolutionStuff.com

How to Copy One Table Data into Another Table using MySQL?

By Hardik Savani • November 5, 2023
PHP MySql

If you are working on php or any php framwork and you want to copy one table into other table by using sql query, so you could do it using simple SELECT and INSERT statement. just you need to think how you can use.

In Following example you can see how to fetch data from "post" table and how to insert into "post_copy" table, so basically you have to select field of one that you want to copy and second one give name of table with proper field that you want insert. But don't forgot to give a name of field otherwise it generate error.

INSERT INTO `post_copy` (name,slug,status)

SELECT name,slug,'1' FROM `post`

Tags: MySql
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Node JS CRUD with MySQL Tutorial Example

Read Now →

How to Create a REST API using Node.js and MySQL?

Read Now →

How to Export Mysql Database using Command Line in Ubuntu?

Read Now →

How to Import Database in Mysql using Command Line in Ubuntu?

Read Now →

PHP MySQL Create Dynamic Treeview Example

Read Now →

PHP MySQL Column Sorting Example Tutorial

Read Now →

PHP MySQL Contact US Form with Validation Example

Read Now →

How to Get Filename from File Path in MySQL Query?

Read Now →

MySQL Calculate Age from Date of Birth Example

Read Now →

How to Check Empty or Null Data using MySQL Query?

Read Now →

How to count unique domains from email address field in MySQL ?

Read Now →

Which MySQL Datatype use for Store an IP Address?

Read Now →

Mysql Hexadecimal Color Code Store in Binary Datatype Example

Read Now →