开发者

mysql select static list

开发者 https://www.devze.com 2023-01-10 04:22 出处:网络
I want to run an INSERT ... SELECT Manual query to insert 1 selected column column with the exact amount of 2 rows from one table to another.

I want to run an

INSERT ... SELECT

Manual

query to insert 1 selected column column with the exact amount of 2 rows from one table to another.

Along 开发者_JAVA百科with this I would like to insert an additional column of static values.

Example

| selected column | static val |
     Variable          4              
     Variable          9

static values 4 & 9 are specified in my php script. Can I do this in 1 mysql query, not using php to store temporary data?


You can use UNION ALL to select from the source table twice like this:

insert into new_table
   select column, 4 from old_table
union all
   select column, 9 from old_table;
0

精彩评论

暂无评论...
验证码 换一张
取 消