简体   繁体   中英

SQL to filter out some data?

I have a database table: mydata

id    content   name
1     1         a
2     2         b
3     2         c
4     13        hhh
5     13        yyyy
6     7         wwww
7     13        iiii
8     7         nnnn
9     8         oooo

It will look at "content" field. If the same value inside "content" show up more than one time, it will display out. Here is final result

id    content   name
2     2         b
3     2         c
6     7         wwww
8     7         nnnn
4     13        hhh
5     13        yyyy
7     13        iiii

Thus how to write this SQL?

select *
from myData
where content in (
  select content
  from myData
  group by content
  having count(*) > 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM