简体   繁体   中英

sql insert statement with nested select

is it possible to do 1 sql statement (insert) which you duplicate one of the inserting value from another table and another value you hard code? for eg, profilepic, i want to duplicate the value from another table data. As for displayname, i would like to hard code. This is my sql statement:

  insert into registration (profilePic, displayname) 
    values ( (select profilePic from registration where userId = 143), 'abc'  );

Error message from mysql :

Error code:1093. You can't specify target table 'registration' for update in from clause. 

Using subqueries within the values clause will not work. You should use the following query instead:

insert into registration (profilePic, displayname) 
select (select profilePic from registration where userId = 143), 'abc'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM