I need to find members that have a caregiver that also has other members. The sample data is like:
| member_id | caregiver_first_name | caregiver_last_name |
|---|---|---|
| 512020204 | AARON | JOHNSON |
| 304030303 | AARON | JOHNSON |
| 002293993 | ABEL | MARTINEZ |
| 383893933 | ALEX | JONES |
The query should return: 512020204 304030303 because they are both tied to AARON JOHNSON
I've tried
SELECT b.member_id FROM (
SELECT member_id,
caregiver_first_name,
caregiver_last_name,
row_number() over (partition by caregiver_first_name,caregiver_last_name order by caregiver_first_name,caregiver_last_name) as rn
FROM caregivers
) b
WHERE b.rn > 1
but this will only give me the second id 304030303 since this was the second row number
How can I solve this?