Postgresql – Select rows, where 3 columns have the same values

postgresql

I have a structure like this:

 col0 col1 col2 col3
 1    1    1    1
 1    1    1    2
 1    1    1    3
 1    2    1    1
 1    2    3    1
 2    3    4    5
 2    3    4    9

I now want to select all rows, that match other rows on the first three columns, so the result of this query using the sample data would be:

 col0 col1 col2 col3
 1    1    1    1
 1    1    1    2
 1    1    1    3
 2    3    4    5
 2    3    4    9

How can I achieve this, I'm kinda stuck at the early beginning…

Thanks in advance!
Alex

Update: Clearified the question. Thanks Erwin.

Best Answer

SELECT
  col0
  ,col1
  ,col2
  ,col3
FROM
  foo
WHERE
  col0 = col1
  and col0 = col2;