Skip to content
Advertisement

Store procedures for delete a repeat records

Hello i have a table in MySQL:

“contracts” where i create a 3 record’s for each client_id, but one bug in the backend create more records on some client_id i try create a store procedure to delete repeat records, example for 3 records:

i need get distinc amount_preapprove for each user, truncate the table and insert result in the store procedures?

I only need a 3 records for each client

enter image description here

Advertisement

Answer

I am unsure whether you really want to retain 3 records per client. In your sample data, it looks more like you are trying to delete duplicates on (cliente_id, amount_preapprove).

If so, you could use the following query:

This query will delete every record for which another record exists with the same cliente_id and amount_preapprove but a smaller id. In other words, this deletes duplicates while retaining the record that has the smallest id.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement