我想使用另一个查询的输出在表中插入多行。
我的插入语句如下所示:
INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id)
VALUES ('Rounded ended! Hit the standings button in the top right corner to check your score.','$group_id','0')
此处$group_id
需要填写,但此查询会返回多少group_ids
个:
SELECT group_id
FROM groups
第二个查询现在返回3 group_ids: 1, 2, 3
这应该导致类似:
INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id)
VALUES ('Rounded ended! Hit the standings button in the top right corner to check your score.','1','0'), ('Rounded ended! Hit the standings button in the top right corner to check your score.','2','0'), ('Rounded ended! Hit the standings button in the top right corner to check your score.','3','0')
答案 0 :(得分:1)
试试这个
INSERT INTO group_messages
(group_message_text,group_message_group_id,group_message_user_id)
select "Rounded ended! Hit the standings button in the top right corner to
check your score.",group_id,0 FROM groups