删除重复记录但保留最旧的记录
我正在使用 Microsoft Access,并希望使用 SQL 查询来删除重复记录。如果存在重复记录,我想保留最旧的交易 ID(或较小的数字)。在这种情况下,我想删除客户 ID 为“1283”的 John Smith 的记录。
| CustID | TransID | FirstName | LastName | Date | Email |
|2523 | 0029 | John | Smith | 22/04/19| [email protected]
|2523 | 1283 | John | Smith | 14/07/21 | [email protected]
|3746 | 2306 | Harry | Potter | 29/01/22 | [email protected]
I'm using Microsoft Access and would like to use a SQL query to remove duplicate records. Where there is a duplicate record, I want to keep the oldest transaction ID (or the lower number). In this scenario, I want to remove John Smith's record with Customer ID "1283."
| CustID | TransID | FirstName | LastName | Date | Email |
|2523 | 0029 | John | Smith | 22/04/19| [email protected]
|2523 | 1283 | John | Smith | 14/07/21 | [email protected]
|3746 | 2306 | Harry | Potter | 29/01/22 | [email protected]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这适用于您的场景,但如果客户更改了电子邮件,您将有两条记录。
This works in your scenario, but if the customer changes their email you will have two records.