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?

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.