My scenario:
My code:
select ID,
Email,
MobileNo,
DeviceId
from (select * from tableuser
order by ID, Email) tableuser_sorted,
(select @pv := '0122338737', @pc= 'DF1234') initialisation
where find_in_set(MobileNo, @pv)
and length(@pv := concat(@pv, ',', ID))
OR find_in_set(DeviceId, @pc) and length(@pc := concat(@pc,',', ID)
Output:
What I am looking for:
The flow will be like this:
User A is a fraudster. Okay, check User A attributes with other users. okay, I found B is sharing the Phone number with A. B will be in the second stage. ok now check User B attributes with other users. okay, I found D is sharing DeviceId with B and so on.
You can use a recursive CTE for this. If you only want fraudsters, something like this should work:
with recursive cte as (
select ID, Email, MobileNo, DeviceId, id as ids
from tableuser
where isfraudsterstatus = 1
union all
select u.id, u.email, u.mobileno, u.deviceid, concat_ws(',', cte.ids, u.id)
from cte join
tableuser u
on u.email = cte.email or
u.mobileno = cte.mobileno or
u.deviceid = cte.deviceid
where find_in_set(u.id, cte.ids) = 0
)
select distinct id
from cte;