如何根据一列中的值在mysql表中选择唯一的值?

时间:2021-03-21 22:43:47

I have table named x

我有一个名为x的表

Here is the sample data in table x

这是表x中的示例数据

Column1____________ Column2______________ Column3

Column1____________ Column2______________ Column3

a ___________________ b______________________c

一个___________________ b______________________c

a2__________________b2______________________c

a2__________________b2______________________c

a3__________________b3______________________c2

a3__________________b3______________________c2

a4_________________b4_______________________c3

a4_________________b4_______________________c3

The result I need in a new table is:

我在新表中需要的结果是:

Column1____________ Column2______________ Column3

Column1____________ Column2______________ Column3

a3__________________b3______________________c2

a3__________________b3______________________c2

a4_________________b4_______________________c3

a4_________________b4_______________________c3

I tried importing the values to a new table and applying a unique index on column 3 but the result i get out of it is

我尝试将值导入到一个新表中,并在第3列上应用惟一索引,但得到的结果是

Column1____________ Column2______________ Column3

Column1____________ Column2______________ Column3

a__________________b______________________c

a__________________b______________________c

a3__________________b3______________________c2

a3__________________b3______________________c2

a4_________________b4_______________________c3

a4_________________b4_______________________c3

1 个解决方案

#1


4  

SELECT * FROM x WHERE Column3 NOT IN 
  (SELECT Column3 FROM x GROUP BY Column3 HAVING COUNT(*) > 1)

#1


4  

SELECT * FROM x WHERE Column3 NOT IN 
  (SELECT Column3 FROM x GROUP BY Column3 HAVING COUNT(*) > 1)