在重复中仅显示一次标题

时间:2012-12-06 20:59:19

标签: mysql

我怎样才能在mysql中获得这个? 我想只在标题中显示一次,在重复中只显示null

+-----------------------------+-------------+-------------+----------+
| title                       | created     | updated     | category |
+-----------------------------+---------------------+-----------------
| What If I Get Sick and Die? | 2008-12-30  | 2009-03-11  | angst    |
|                             | 2009-02-28  | NULL        | humor    |
|                             | 2009-03-02  | NULL        | advice   |
|                             | 2009-03-17  | NULL        | humor    |
| The Size of Our Galaxy      | 2009-04-03  | NULL        | science  |
|                             | 2009-03-02  | NULL        | advice   |
|                             | 2009-03-17  | NULL        | humor    |
|                             | 2009-04-03  | NULL        | science  |
+-----------------------------+---------------------+-----------------

1 个答案:

答案 0 :(得分:0)

您可以使用以下查询来实现此目的:

SELECT CASE WHEN
(
    SELECT t1.id 
    FROM tablename t1 
    WHERE t1.title = t.title LIMIT 1
) = t.id THEN t.title
ELSE null END AS title
,t.created
,t.updated
,t.category
FROM tablename t