删除title字段相同的行
如果content字段有值则优先保留,
如果title相同的行,且content都没有内容或者都有内容,保留ID小的举例如下:原表
id title content
1 狮子 在路上
2 狮子
3 老虎
4 老虎 嘻嘻嘻
5 豹子 哈哈哈
6 豹子
7 狮子 在路上
8 骆驼
9 骆驼结果
id title content
1 狮子 在路上
4 豹子 哈哈哈
5 老虎 嘻嘻嘻
8 骆驼
如果content字段有值则优先保留,
如果title相同的行,且content都没有内容或者都有内容,保留ID小的举例如下:原表
id title content
1 狮子 在路上
2 狮子
3 老虎
4 老虎 嘻嘻嘻
5 豹子 哈哈哈
6 豹子
7 狮子 在路上
8 骆驼
9 骆驼结果
id title content
1 狮子 在路上
4 豹子 哈哈哈
5 老虎 嘻嘻嘻
8 骆驼
(
select *
from tb A
where not exists (select 1 from tb where A.title=title and A.id>id)
) T1 left join
(
selet * from tb where content is not null
)T2
on T1.title=T2.title
如果left join 的 是selet * from tb where content is not null 那么结果集是不是连骆驼这条数据也显示不出来了?