Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql中查询/删除重复数据 #5

Open
Albatronhenry opened this issue Nov 9, 2018 · 0 comments
Open

sql中查询/删除重复数据 #5

Albatronhenry opened this issue Nov 9, 2018 · 0 comments

Comments

@Albatronhenry
Copy link
Owner

Albatronhenry commented Nov 9, 2018

参考链接
针对没有主键的重复数据

表test20181109
----------------
id    -    name
2     |      c
1     |      a
2     |      b
1     |      a
2     |      b
----------------

查询重复数据:

select id from test20181109 group by id having `count(1)`>1

id
1
2

删除重复数据,并保留其中一条

delete from test20181109 where id in (
select id from test20181109 group by id having count(1)>1
) and rowid not in (
 select min(rowid) test20181109 group by id having count(1)>1
)

处理后的数据:

----------------
id    -    name
2     |      c
1     |      a
----------------
Repository owner locked as resolved and limited conversation to collaborators Nov 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant