Select where count of one field is greater than one

后端 未结 9 1147
说谎
说谎 2020-12-07 23:57

I want to do something like this:

SELECT * 
  FROM db.table 
 WHERE COUNT(someField) > 1

How can I achieve this in MySql?

9条回答
  •  醉梦人生
    2020-12-08 00:22

    You can also do this with a self-join:

    SELECT t1.* FROM db.table t1
    JOIN db.table t2 ON t1.someField = t2.someField AND t1.pk != t2.pk
    

提交回复
热议问题