当前位置:网站首页>Leetcode Day5 delete duplicate email
Leetcode Day5 delete duplicate email
2022-07-28 19:44:00 【wyqgg123】
196. Delete duplicate email
The difficulty is simple
Write a SQL Inquire about , To delete Person All duplicate email addresses in the table , The duplicate mailbox only keeps Id Minimum the .
±—±-----------------+
| Id | Email |
±—±-----------------+
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
±—±-----------------+
Id It's the primary key of this table .
for example , After running your query , above Person The table should return the following lines :
±—±-----------------+
| Id | Email |
±—±-----------------+
| 1 | [email protected] |
| 2 | [email protected] |
±—±-----------------+
Tips :
perform SQL after , The output is the whole Person surface .
Use delete sentence .
Answer key :
It is not difficult for us to see from the meaning of the title , This question needs to use delete Statement to delete duplicate Email value , Here we can disassemble the subject , First, repeat Email Find out , Then find out Email Delete the result .
1、 Find duplicate Email result
The implementation here is to realize query repetition through self table connection Email, The connection condition is a.Email be equal to b.Email, After connection query , We need to judge ourselves in terms of conditions Email Equal rows are deleted , What you get in this way is repetition Email.
select a.*
from Person a
left join Person b
on a.Email = b.Email
where a.Id > b.Id
The operation results are shown in the following table :
| id | |
|---|---|
| 3 | [email protected] |
2、 Delete the queried data
All we need to do here is select Replace statement with delete Sentence can be used
sql Code
delete a.*
from Person a
left join Person b
on a.Email = b.Email
where a.Id > b.Id
Data in the table after deleting duplicate data :
| Id | |
|---|---|
| 1 | [email protected] |
| 2 | [email protected] |
边栏推荐
猜你喜欢

Cloud computing notes part.1 - system management

Sword finger offer II 109. unlock the password lock

Servlet learning notes

这个客制化键盘,秀翻我了~

High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation

WPF 实现带蒙版的 MessageBox 消息提示框

Rust 入门指南(crate 管理)

使用SaltStack自动化部署Zabbix

11. Learn MySQL union operator

Rust Getting Started Guide (modules and engineering structures)
随机推荐
Servlet learning notes
亚马逊推出Amazon One手掌支付系统,非接触式掌静脉识别市场有望爆发
云计算笔记part.2——应用管理
开盘暴涨215%!国产信号链芯片企业芯海科技登陆科创板
How navicate modifies the database name
Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization
彻底理解位运算——左移、右移
npm安装和卸载全局包
Rust 入门指南(rustup, cargo)
并发程序设计,你真的懂吗?
MySQL8 Encrypting InnoDB Tablespaces
Transformer for anomaly detection - instra "painting transformer for anomaly detection"
WPF 实现带蒙版的 MessageBox 消息提示框
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
英语文章翻译-英语文章翻译软件-免费批量翻译
leetcode day5 删除重复的电子邮箱
中国首枚芯片邮票面世:内置120um超薄NFC芯片
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
Quickly install torch spark, torch geometric and other packages in moment pool cloud
leetcode day4 部门工资最高的员工