Removing Duplicate Rows While Preserving Oldest Entries
In your table containing user submission data, duplicate entries have accumulated based on the subscriberEmail field. To ensure data integrity, you want to remove these duplicate rows while retaining the original submissions.
Solution:
<code class="sql">delete x from myTable x join myTable z on x.subscriberEmail = z.subscriberEmail where x.id > z.id</code>
Explanation:
Additional Considerations:
To prevent future duplicate insertions, consider creating a UNIQUE index on the subscriberEmail column. This will enforce the uniqueness of email addresses in the table.
The above is the detailed content of How to Remove Duplicate Rows in a Table While Keeping the Oldest Entry?. For more information, please follow other related articles on the PHP Chinese website!