2

I'm pretty new to PostgreSQL right now and am trying to search through a column and find where in that column duplicate strings exist.

For example, if I have the following table:

Col_1  Col_2  Col_3
1      cat    45
2      dog    67
3      bird   77
4      cat    90

So essentially, without knowing which specific strings to look for, I want to write a query that would pull both instances of 'cat' from col_2 because they are the same.

Can anyone help out with some suggestions of where to begin/how to do this?

Gabriel's Messanger
  • 3,213
  • 17
  • 31
TheVideotapes
  • 383
  • 2
  • 3
  • 9

1 Answers1

1
select
  Col_2,
  count(*)
from 
  your_table
group by
  Col_2
having
  count(*) > 1

Should do the trick. Well, it will show you which values of Col_2 contain duplicates anyways.

http://sqlfiddle.com/#!15/1d685/1

Please use snake_case in PostgreSQL (all lower chars).

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152