简单的mysql选择问题

时间:2012-07-08 15:18:07

标签: mysql

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

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

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

3 个答案:

答案 0 :(得分:6)

Select title, content
From table_name
Where title In
    (Select title From Table
     Group By title
     Having COUNT(*) > 1)

(来自Multiple NOT distinct

答案 1 :(得分:0)

根据我的理解,SQL查询应如下所示:

SELECT post_title, content
FROM post
GROUP BY post_title, content

答案 2 :(得分:0)

尝试使用

之类的东西
SELECT total, content FROM post 
   WHERE id IN ( 
    SELECT id FROM post 
         GROUP BY post_title 
         HAVING count(post_title) > 1 
   )