I have a following table structure in Postgres:
id | account_id | plan_id | active
----+------------+---------+--------
1 | 0cYd7Ak | 1 | f
2 | Uk02q1d | 1 | t
3 | eRlk810 | 2 | f
4 | Uk02q1d | 2 | t
5 | 0cYd7Ak | 1 | t
6 | yT3nv3p | 3 | t
How I can select all row where account_id
occurs more than once? For the example above it will return rows 1, 2, 4, 5
I tried this one query, but it does not return what I expect:
select * from table_name t1
where (select count(*) from table_name t2
where t1.account_id = t2.account_id) > 1
order by t1.account_id;