SQL Server inner join to that query again inner join again the same -
we working mlm project. basic idea of project like
- a has been introduced
- b has been introduced a
- c has been introduced b
- d has been introduced c
my sql server table structure like
user_details
https://i.stack.imgur.com/xchgd.jpg
now theoretically
a's team members => b , c , d b's team members => c , d c's team member => d d's team member => null (he doesn't have team members yet)
using sql query, how can find team members of 'a'?
you can use recursive select statement follows:-
declare @leadname char(1) = 'a'; team ( select id, f_name, l_name, introduced_by mlm f_name = @leadname union select m.id, m.f_name, m.l_name, m.introduced_by mlm m join team t on m.introduced_by = t.id ) select * team f_name <> @leadname;
here variable @leadname
f_name
of desired root ('a' in case).
Comments
Post a Comment