MySQL 你如何插入一个带有返回多行的 SELECT 子查询的表?

2022-01-23 00:00:00 insert-into select subquery mysql

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"
     ),
    );

我想要使用从此子查询返回的所有结果填充新表.如何在不收到 ERROR 1242 (21000): Subquery return more than 1 row

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

将静态字符串 Henry 与您的 SELECT 查询结合起来.

Combine the static string Henry with your SELECT query.

相关文章