mysql - Merge and then Delete duplicate entries -
I have my SQL database with some duplicate entries, they have the same area - phones but they have grounds too were different. For example, I have two entries with the same phone, but the rating in the first entry is the = default_value and the second entry has the rating field = 5. So I have to merge these entries and then only delete the duplicate ...
More general examples:
Entry 1.phone == 123 Entry 1.phone = = Entry 2.Phone entry1 Writing! = Entry 2.Phone Entry 1 Rating == Default_View (0) Entry 2. Riting == 5 Merge Entry 1.phone == 123 entry 1. Rating == 5 Entry 2 is destroyed
It seems as if you were actually There is no need to merge any records if you are trying to update the first record with a non-default rating. I think you can delete any record with default rating.
Select one * Join an inside TBL at tbl B on a.Phone = b.Phone and a.Rating & lt; B.Rating one from one TBL joining an internal tbl b on one. Phone = B Phone and A.Rating & lt; B.Rating If you need to update the record first and delete the second record, then you can do something similar if you have an autoincrement ID. The next example is that if there is an ID, then what I will do to update the record first. This is only reliable if you have just repeated the phone number once.
set a.Rating = b. Update tbl to an internal join tbl Phone = B Phone and A.Rating & lt; B. Writing and AIID & lt; BID One TBL with one join entry and TLB B. Phone = B.Phone and A.Rating = B.Rating and B.ID & gt; A.ID
Hope this will be helpful.
- Rethhelien
Comments
Post a Comment