MySQL如何将具有SELECT子查询的表插入返回多行的表? [英] MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?

查看:184
本文介绍了MySQL如何将具有SELECT子查询的表插入返回多行的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MySQL如何将带有SELECT子查询的表插入到返回多行的表中?

MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?

  INSERT INTO Results
    (
     People,
     names,
    )
    VALUES
    (
     (
       SELECT d.id
       FROM Names f
       JOIN People d ON d.id  = f.id
     ),

     (
      "Henry"
     ),
    );

想要,使用该子查询返回的所有结果填充新表.如何在不出现错误1242(21000)的情况下执行此操作:子查询返回多于1行

I WANT to populate the new table with all results returning from this subquery. How do I do this without getting a ERROR 1242 (21000): Subquery returns more than 1 row

推荐答案

INSERT INTO Results (People, names )
   SELECT d.id, 'Henry'
   FROM Names f
   JOIN People d ON d.id  = f.id

通过SELECT查询将静态字符串Henry组合在一起.

Combine the static string Henry with your SELECT query.

这篇关于MySQL如何将具有SELECT子查询的表插入返回多行的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆