Hi I'm currently trying to create a query to group customers together.
I'm currently wanting to group by "Phone Number", "Email" and maybe some other fields in the future.
My problem is that I may want to group rows which aren't directly linked but have mutual rows.
For example, in this diagram we can see that Customer 2 and Customer 5 are in no way related at all, however they both share connections with Customer 1 which would then allow them to group together.
Here is another View:
CustomerId | FullName | PhoneNumber | Email
---------------------------------------------------------------------------------
1 | Bill Smith | 01612345678 | BillS@SqlTeam.com
2 | Kelly Smith | 01612345678 | KellyS@SqlTeam.com
3 | Kevin Roach | 07111111111 | KevinR@Example.com
4 | Chris Ronald | 07222222222 | ChrisR@Blog.co.uk
5 | Bill Smith | 07987654321 | BillS@SqlTeam.com
We can see that Customer 2 is connected to Customer 1 through a mutual Phone Number, and Customer 5 is connected to 1 through a mutual Email Address. However Customer 2 and Customer 5 share no information which would've originally grouped them.
My reasoning for needing this functionality is that one person / household could have multiple customer accounts all with differing information therefore I am trying to group them up as best as I can with as much mutual information as possible.
Thanks all, hopefully I have explained my situation well enough!