mysql - SQL: insert into -


for example, table has 3 columns , 10 rows.

id     name     parentid 1    parent #1    null 2    child #1      1 3    child #1      1  4    child #1      1 5    child #2      2 6    child #2      2 7    child #2      3 8    child #2      3 9    child #2      3 10   child #2      3 

and need insert new row, "know" id of element inserted new element, not parentid value.

so, example, add new element child #1 id = 3, has parentid = 1. , have id value. when insert element table need give him right parentid. query must use?

insert `tree`(`id`, `name`, `parentid`)  values (11, "inserted element", "and here want give new element parentid of element id 3, 1"); 

thanks help!

usually needs done via application level in same query can use insert .. select from

insert `tree`(`id`, `name`, `parentid`) select  11, "inserted element", parentid from(  select parentid tree id = 3 )x 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -