开发者

How to select just unique values into a mysql table based on the value in one column?

开发者 https://www.devze.com 2023-03-07 02:53 出处:网络
I have table named x Here is the sample data in table x Column1____________ Column2______________ Column3

I have table named x

Here is the sample data in table x

Column1____________ Column2______________ Column3

a ___________________ b______________________c

a2__________________b2______________________c

a3__________________b3______________________c2

a4___________开发者_JAVA技巧______b4_______________________c3

The result I need in a new table is:

Column1____________ Column2______________ Column3

a3__________________b3______________________c2

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

Column1____________ Column2______________ Column3

a__________________b______________________c

a3__________________b3______________________c2

a4_________________b4_______________________c3


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

精彩评论

暂无评论...
验证码 换一张
取 消