sql >> Database >  >> RDS >> Mysql

Ouderboom in mysql-tabel (while-loop)

U kunt dit bereiken met Procedures..

CREATE PROCEDURE `root_connect`(IN init char(1),OUT str char(15))
BEGIN
    set @startChar:=(select category_id from tableName where parent_id = init);
    set @endloop := "no";
    set @fullchar:= @startChar;
    set @newchar:= "";  
    if (@startChar !="-" OR @startChar =null) then 
        WHILE (@endloop = "no") DO                  
            set @newchar :=(select category_id from tableName where parent_id = @startChar);       
            if(@newchar = '-') THEN
                set @endloop := "yes";
            else
                set @fullchar:= concat(@fullchar,"-",@newchar);
            end if;         
            set @startChar := @newchar;     
        END WHILE;
    end if;
        select @fullchar;
END


  1. Vreemde/geaccentueerde tekens in sql-query

  2. PostgreSQL-extensie installeren op alle schema's

  3. Hoe te mysql escapen in magento?

  4. mysql-volgorde op max komt overeen met veldwaarde