avatar
s*n
1
I got a sql problem:
here is a database table ------
id(PK) name
1 mark
2 mike
3 mary
4 mike
5 mary
how can I select then name "mary" and "mike" out because they appear twice?
Thanks a lot!
avatar
j*n
2
the table have different id, can be restrict by a "where id = xxxx"
eg.
select * from table_name where id=2 // the first mike
select * from table_name where id=4 // second mike

【在 s*********n 的大作中提到】
: I got a sql problem:
: here is a database table ------
: id(PK) name
: 1 mark
: 2 mike
: 3 mary
: 4 mike
: 5 mary
: how can I select then name "mary" and "mike" out because they appear twice?
: Thanks a lot!

avatar
n*a
3
If you want any name that appears more than once,
select name from table_name group by name having count(*) > 1
select name from table_name group by name having count(distinct id) > 1
If you want name that appears exactly twice
select name from table_name group by name having count(*) = 2
select name from table_name group by name having count(distinct id) = 2

【在 s*********n 的大作中提到】
: I got a sql problem:
: here is a database table ------
: id(PK) name
: 1 mark
: 2 mike
: 3 mary
: 4 mike
: 5 mary
: how can I select then name "mary" and "mike" out because they appear twice?
: Thanks a lot!

avatar
s*n
4
this is exactly what I want. thanks.

twice?

【在 n********a 的大作中提到】
: If you want any name that appears more than once,
: select name from table_name group by name having count(*) > 1
: select name from table_name group by name having count(distinct id) > 1
: If you want name that appears exactly twice
: select name from table_name group by name having count(*) = 2
: select name from table_name group by name having count(distinct id) = 2

avatar
v*d
5
I think it's simple and effective to meet your requirement:
Select distinct(name) from tb

【在 s*********n 的大作中提到】
: this is exactly what I want. thanks.
:
: twice?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。