如何在mysql中通过insert向表select from table中添加额外的行?

如何在mysql中通过insert向表select from table中添加额外的行?,mysql,Mysql,我有两个表:表1包含一个post,表2包含映射到post的所有用户。现在我想在表1中插入post,我将获得一个post_id,然后我将插入所有映射到post的用户,他们都具有user_id和post_id insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) select '12345', `user_id`, '0' from `users` where username in ("A","B","C") 现在我想插

我有两个表:表1包含一个post,表2包含映射到post的所有用户。现在我想在表1中插入post,我将获得一个post_id,然后我将插入所有映射到post的用户,他们都具有user_id和post_id

 insert into `post_users_map` (`post_id`,`user_id`,`is_owner`)
 select '12345', `user_id`, '0' from `users`
 where username in ("A","B","C")
现在我想插入
(“12345”,“123',1)
,作为另一行以及select结果


任何建议都将受到感谢。

只需使用union添加选择即可

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select '12345', `user_id`, '0' 
from `users` where username in ("A","B","C")
UNION 
select '12345', '123, '1' 

只需使用union添加select

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select '12345', `user_id`, '0' 
from `users` where username in ("A","B","C")
UNION 
select '12345', '123, '1' 

只需在选择的插入之后添加另一个具有值的插入

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select 12345, user_id, 0
from `users` 
where username in ('A','B','C');

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) values 
(12345, 123, 1);
另外,
允许在同一
插入
中包含更多元组

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) values 
(12345, 124, 1),
(12345, 125, 1),
(12345, 126, 1);
或者,您可以使用UNION ALL从2个具有不同is_所有者的select中插入用户id

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select 12345, user_id, 0
from `users` 
where username in ('A','B','C')
UNION ALL
select 12345, user_id, 1
from `users` 
where username in ('D');

只需在选择的插入之后添加另一个具有值的插入

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select 12345, user_id, 0
from `users` 
where username in ('A','B','C');

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) values 
(12345, 123, 1);
另外,
允许在同一
插入
中包含更多元组

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) values 
(12345, 124, 1),
(12345, 125, 1),
(12345, 126, 1);
或者,您可以使用UNION ALL从2个具有不同is_所有者的select中插入用户id

insert into `post_users_map` (`post_id`,`user_id`,`is_owner`) 
select 12345, user_id, 0
from `users` 
where username in ('A','B','C')
UNION ALL
select 12345, user_id, 1
from `users` 
where username in ('D');

工会怎么样?你们草莓,工会成功了。工会怎么样?你们草莓,工会成功了。