MySQL:从select distinct中选择所有行

时间:2017-10-05 10:31:56

标签: mysql sql select distinct

我想做一个特定的查询

select distinct name 
from tablename

删除重复项。但这只给了我名字。从'中选择表格中的不同名称'我希望所有列都返回一个条件:

select * 
from tablename 
where value= 1

我试过了:

select * 
from tablename 
where value = 1 and exists (select distinct name 
                            from tablename)

不幸的是,它返回的数据与:

相同
select * 
from tablename 
where value = 1

这意味着我的查询存在根本缺陷。

有人可以帮助我查询。提前谢谢。

2 个答案:

答案 0 :(得分:0)

你能试试这个console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.connection));

吗?

答案 1 :(得分:0)

此查询将为您提供重复项的ID:

select distinct id
from table1
group by id
having count(id)>1

你可以把

having count(id)=1

如果你想知道没有重复的那些