MySQL select records for duplicates using multiple columns

前端 未结 2 1615
别那么骄傲
别那么骄傲 2020-12-08 02:11

I would like the select records from a table, or insert them into a new blank table where multiple of the columns is the same as another record in the database. The problem

2条回答
  •  囚心锁ツ
    2020-12-08 02:51

    why don't you try using union or creating temporary table. but personally, i do recommend using union than that of creating temporary table cause it would take you a longer time doing that. try doing this:

      select field1, field2 from(
       select '' as field2, field1, count(field1) as cnt FROM list GROUP BY field2 HAVING cnt > 1
        union
        select ''as field1, field2, cound(field2) as cnt from list group by field1 having cnt > 1
      )
    

    hope this make sense.:)

提交回复
热议问题