mysql返回表中某行或者多行的重复值操作教程
程序员文章站
2022-06-20 22:55:56
表tb_question
type
answer
a
1
a
1
b
2
b
3
c
4
1、作用于单列
select distinct [列名] from [表名]...
表tb_question
type | answer |
a | 1 |
a | 1 |
b | 2 |
b | 3 |
c | 4 |
1、作用于单列
select distinct [列名] from [表名];
例如:select distinct type from tb_question ;
运行之后:
type |
a |
b |
c |
2、作用于多列
select distinct [列名1],[列名2] from [表名];
例如:select distinct type,answer from tb_question ;
运行之后:
type | answer |
a | 1 |
b | 2 |
b | 3 |
c | 4 |
注:distinct必须放在开头