Mysql 具有相同属性的两个或多个SQL语句

Mysql 具有相同属性的两个或多个SQL语句,mysql,sql,Mysql,Sql,我有一张这样的桌子: id value has_other color 1 banana 0 yellow 2 apple 1 red 3 apple 1 green 4 orange 0 orange 5 grape 0 red 6 grape 0 green 我想做一个查询,选择“has_other”=0的所有条目,但

我有一张这样的桌子:

id  value    has_other  color
1   banana   0          yellow
2   apple    1          red
3   apple    1          green
4   orange   0          orange
5   grape    0          red
6   grape    0          green
我想做一个查询,选择“has_other”=0的所有条目,但还有其他具有相同“value”和“has_other”值的条目(基本上是为了查找重复项)

编辑:添加了一些条目。对于上述示例,查询应返回这些值:

5, grape, 0, red
6, grape, 0, green
有什么想法吗


干杯

这将返回您想要的结果:

SELECT t.*
FROM myTable t
INNER JOIN (
  SELECT value
  FROM myTable
  WHERE has_other = 0
  GROUP BY value
  HAVING count(*) > 1
  ) a ON a.value = t.value
WHERE t.has_other = 0;

如果你已经展示了你的预期结果,那就太好了。我认为您希望从您的数据中得到以下结果:

那么,要获得不重复的结果,您必须使用
distinct
函数。这是剧本:

select distinct(f.value), f.has_other
from fruit f
where f.has_other=0

我希望这能帮助你。

所以你想看看:香蕉、苹果、橘子;或者香蕉、橙色?@sqrfv在本例中,它应该不返回任何内容。但是如果两个苹果都有其他值0,它应该返回这两个。我想返回all has_other=0,其中存在2个或更多具有相同值且在table@MostyMostachohas_other为0或1。这只是一个问题,看看是否还有其他条目具有相同的名称value@MostyMostacho这种情况在我的datasetit中不存在,它似乎返回了正确的行,但每个行只返回一行(在上面的示例中,只有一个葡萄),非常感谢,它是有效的!虽然它在+180.000行上运行非常慢,但它也会返回所有只有一个具有相同值的条目
select distinct(f.value), f.has_other
from fruit f
where f.has_other=0