MySQL查询某个字段不重复的所有记录

376次阅读
没有评论

MySQL查询某个字段不重复的所有记录

假设现在有如下N条记录 表叫book

id author title

1 aaa AAA

2 bbb BBB

3 ccc CCC

4 ddd DDD

5 eee AAA

现在想从这5条记录中查询所有title不重复的记录

select a.* from book a right join (
select max(id) id from book group by title) b on b.id = a.id
where a.id is not null

如果选第一条符合的记录,那么用min(id)就行了

select a.* from book a right join (
select min(id) id from book group by title) b on b.id = a.id
where a.id is not null

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python教程2022-10-19发表,共计349字。
新手QQ群:570568346,欢迎进群讨论 Python51学习