Anand_K47
Anand_K47

Reputation: 1

How to INSERT all record from one table to another in mysql

I am beginner please help to copy all records from 'first' table to 'second' table.

first table has 6 columns

| Item_Id | Item_Name | Unit | Quantity | Rate | Total_Amt |

And second one has one more additional column

| Sr_No | Item_Id | Item_Name | Total_Unit | Total_Quantity | Rate | Total_Amt |

Upvotes: 0

Views: 120

Answers (2)

Himanshu
Himanshu

Reputation: 32602

Try INSERT INTO...SELECT

INSERT INTO 
    todayssales(Item_Id, Item_Name, Total_Unit, Total_Quantity, Rate, Total_Amt)
SELECT Item_Id, Item_Name, Unit, Quantity, Rate, Total_Amt
  FROM new_bill

In your second table (todayssales) you can set AUTO_INCREMENT on Sr_No so that can be filled automatically.

See this SQLFiddle

Upvotes: 4

aizaz
aizaz

Reputation: 3062

Try this query

insert into todayssales( Item_Id, Item_Name, Total_Unit, Total_Quantity, Rate, Total_Amt)
 select Item_Id, Item_Name, Unit, Quantity, Rate, Total_Amt
  FROM new_bill

Upvotes: 1

Related Questions