1

The table has 30+ columns and there are many duplicated row data like this:

col_1  col_2  col_3
1      2      2
2      3      2
1      2      2
3      2      2
1      2      2
2      3      2
3      2      2

I want to select all data and filter these duplicated rows, after filtering, the result is

col_1  col_2  col_3
1      2      2
2      3      2
3      2      2

I found DISTINCT and GROUP BY work but I should type many column names. Are there any easier methods available?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
GoingMyWay
  • 16,802
  • 32
  • 96
  • 149
  • Possible duplicate of [How do I (or can I) SELECT DISTINCT on multiple columns?](https://stackoverflow.com/questions/54418/how-do-i-or-can-i-select-distinct-on-multiple-columns) – Hong Van Vit Oct 23 '17 at 02:39
  • @HồngVănVít, The answers from the link you provided don't work for me, `distinct * ` is what I need. – GoingMyWay Oct 23 '17 at 04:49

2 Answers2

2

easiest way

select distinct * from table

or

select distinct col_1, col_2, col_3 from table
Przemo
  • 81
  • 2
1

Adding to @Przemo answer, you better use select distinct * from table,

You can similarly use select unique * from table

Specify DISTINCT or UNIQUE if you want the database to return only one copy of each set of duplicate rows selected.

But not in Group by,

Group by can't be used with *, You must specific column names:

GROUP BY { column-Name [ , column-Name ]*

column-Name must be a column from the current scope of the query

Ori Marko
  • 56,308
  • 23
  • 131
  • 233