Select rows with different id but same values I would like to find all records with the same values but different id's.

Here is the data I currently have:

+------+------+
|id    |userid|
+------+------+
|1     | 5    |
+------+------+
|1     | 8    |
+------+------+
|2     | 10   |
+------+------+
|2     | 12   |
+------+------+
|3     | 5    |
+------+------+
|3     | 8    |
+------+------+
|4     | 8    |
+------+------+
|4     | 13   |
+------+------+


id 1 has the same exact userid values as id 3. I want to see all the tables that have the same userid values.

Here is the results I would like it to return:

+------+------+
|id    |userid|
+------+------+
|1     | 5    |
+------+------+
|1     | 8    |
+------+------+
|3     | 5    |
+------+------+
|3     | 8    |
+------+------+


Im using Postgres 9.6.
First you have to filter the userid that appears more than one time:

select
userid
from table
group by userid
having count(1) &gt; 1


This will return:

userid
------
     5
     8


Now using this as a subquery you can select the complete result you want:

select 
*
from table
where userid in (
  select
  userid
  from table
  group by userid
  having count(1) &gt; 1
)