sql - MySQL Multilevel parent child SP and IN Clause -
i working on table referrals
contains parent child relations
i need parent -> children -> ther children -> ....
for above table data desired result is
i have seen code sof didn't how working , tried myself easy logic in mind unfirtunately not working strange reason
i have written stored procedure stuck issue in clause
delimiter $$ drop procedure if exists `gethierarchy3`$$ create definer=`root`@`localhost` procedure `gethierarchy3`() begin declare idss varchar(225); set @currentparentid := 999999; set @lastrowcount := 0; ## ## insert referrals_copy select * referrals uid1 = @currentparentid; set @lastrowcount := row_count(); ## b ## select group_concat(uid2) @idss referrals uid1 = @currentparentid; #select @lastrowcount; select * referrals_copy; while @lastrowcount > 0 select "here"; select @idss; ## c ## insert referrals_copy select uid1, uid2 referrals uid1 in (@idss); set @lastrowcount := row_count(); #set @ids := null; select @idss; select group_concat(uid2) referrals uid1 in (@idss); select @idss; set @lastrowcount := 0; end while; -- return final set select * referrals_copy; end$$ call gethierarchy3();
first children main parent want in first query a
, working fine
then, gets children of main parent variable @idss
query b
, working fine
then in loop use variable idss
in query children query c
, put them in resultant table... problematic part
here first iteration have 1111,2222
in variable idss
should result in insertion of values {3333, 4444} child of 1111, , {5555} child of 2222
in table put children of 1111
ie 3333,4444
but, not 5555
i tried replace variable query c
check , worked fine values 1111,2222' within
in claues`
any idea on why in clause not accepting comma separated values group concat or idea on fixing code
regards
try find_in_set(uid1,@idss)
you have replace query part
select group_concat(uid2) referrals uid1 in (@idss);
into this
select group_concat(uid2) referrals find_in_set(uid1,@idss);
i hope work you....
Comments
Post a Comment