Code for replacing and deleting data from MySQL db

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
mercy83
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Dec 19, 2018 1:39 am

Wed Dec 19, 2018 2:49 am

Hello everybody.
I have a problem. In my database I need to delete special rows of duplicated contractors from "contractors" table. Last (which always have the same individual vat_number) added duplicated contractor must only stay. Any other rows with duplicated contractor_id are to delete.
Second thing is that this old contractors (contractor_id) are in invoices in the second table "orders". I need a script to connect to mysql database and find all invoices having old contractor id and replace it all to last created contractor_id with the same vat_number.
Can somebody help me with this?

I'm running PHP 5 + MySQL 5.5.59

Here's the example:
http://sklep.certpol.pl/files/mysql_tables.jpg

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 775
Joined: Mon Feb 22, 2016 5:52 pm

Wed Dec 19, 2018 8:21 am

I suggest re-writing the table(s) involved and transfer the data from the old tables, putting the correct constraints and controls in place to prevent further duplication.

You'll need to do a lot of testing before you make the final transfer.

While you're at it, you would be wise to update to PHP 7.

Post Reply