I am currently working on a webbased systen using a Mysql db.
I realised that I had initially set up the columns within the tables incorrectly and
I now need to move the data from one table column (receiptno) in table (clients) into a similar table column(receiptno) in table (revenue).
I am still quite inexperienced with Mysql and therefore I dont know the the mysql syntax to accomplish this.
Can I get some help on it.
Thanks
To copy from one column to another, you can use INSERT INTO SELECT statement.
Click the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy. Click the tab for the table into which you want to copy the columns. Select the column you want to follow the inserted columns and, from the Edit menu, click Paste.
UPDATE table SET columnB = columnA; This will update every row. This will also work if you want to transfer old value to other column and update the first one: UPDATE table SET columnA = 'new value', columnB = columnA . Like other answer says - don't forget the WHERE clause to update only what's needed.
If you simply wanted to insert the data into new records within the revenue
table:
INSERT INTO revenue (receiptno) SELECT receiptno FROM clients;
However, if you want to update existing records in the revenue
table with the associated data from the clients
table, you would have to join the tables and perform an UPDATE
:
UPDATE revenue JOIN clients ON **join_condition_here**
SET revenue.receiptno = clients.receiptno;
Learn about SQL joins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With