insert, copy a part of the data table into another table

Work often encounter insert a data, which may contain a fixed value, it may be the result of the query another table
to solve the problem of two cases:
1, table2 when there is:

insert into table1 (x1,x2) values('a',(select x from table2 where x=x))

2, when the absence of table2:

insert into table1(x1,x2) select 'a' , x from table1 where where x=x

Reproduced in: https: //www.jianshu.com/p/a9304c4c940d

Guess you like

Origin blog.csdn.net/weixin_34066347/article/details/91190938
Recommended