Reputation:
I have the following table in my database:
Table name: INSURANCE TABLE
ID | Policy
1 | 34564
2 | 67548
3 | 34564
4 | 98271
5 | 90198
6 | 98271
I am looking for a sql query that will compare the Policy column values in all 5 rows and return those rows which have a value equal to atleast one other row.
For the table above I should get the following result set:
1 | 34564
3 | 34564
4 | 98271
6 | 98271
I would appreciate responses on how to write this query.
Upvotes: 1
Views: 4740
Reputation: 848
If I understand you, you want to group by Policy, discarding unique values:
select * from your_table where Policy in (
select Policy from your_table group by Policy having count(*) > 1
);
Upvotes: 4