【问题标题】:Simple mysql select issue简单的mysql选择问题
【发布时间】:2012-07-08 15:18:07
【问题描述】:

我正在尝试选择数据库中所有重复的行。我有下表:

title     content
aa          hahaha
bb          weeeee
cc          dddddd
aa          ggggg
aa          ggggggee
dd          hhhhhhh
bb          ggggggg

我的查询是

select count(post_title) as total, content from post group by post_title

它只会显示

 total        content
    3        hahaha
    2        weeeeee

但我想展示类似的东西

total        content
aa          hahaha
aa          ggggg
aa          ggggggee
bb          weeeeeee
bb          geeeeeee

不知道该怎么做,我认为这可能很简单。感谢您的帮助。

【问题讨论】:

    标签: mysql


    【解决方案1】:
    Select title, content
    From table_name
    Where title In
        (Select title From Table
         Group By title
         Having COUNT(*) > 1)
    

    (来自Multiple NOT distinct

    【讨论】:

      【解决方案2】:

      据我了解,SQL 查询应如下所示:

      SELECT post_title, content
      FROM post
      GROUP BY post_title, content
      

      【讨论】:

      • 它不会显示所有重复的标题和内容。不过谢谢
      【解决方案3】:

      尝试类似的东西

      SELECT total, content FROM post 
         WHERE id IN ( 
          SELECT id FROM post 
               GROUP BY post_title 
               HAVING count(post_title) > 1 
         )
      

      【讨论】:

      • 为什么不呢?这个查询返回什么,你需要什么?
      • 您的查询选择 id 而不是标题。请参阅已接受的答案。 :)
      猜你喜欢
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2012-01-30
      相关资源
      最近更新 更多