Ambivert
Ambivert

Reputation: 11

How to insert data from one table into another table?

I'm new to python and I was trying to insert data from one table to another and the code is executing but it is not reflecting any changes in new table in which I want to insert data.

import mysql.connector
conn=mysql.connector.connect(user='root',password='',host='localhost',database='xyz')
mycursor=conn.cursor()
mycursor.execute("insert into newTable select * from oldTable  group by mac,date,time order by mac")

Upvotes: 1

Views: 1725

Answers (2)

Lekha B
Lekha B

Reputation: 75

I suppose it is because you are not committing the changes. Use the below code and see if it works.

conn.commit()

You need to use conn because that is the variable name for your connection to the database. A commit must be sent to the server, which in turn will commit your changes.

Upvotes: 1

Santhosh Kumar
Santhosh Kumar

Reputation: 543

You need to add commit() to make the changes.

conn.commit()

Upvotes: 0

Related Questions