欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql返回表中某行或者多行的重复值操作教程

程序员文章站 2023-11-15 17:53:40
表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必须放在开头