MySQL 如何使用返回多行的 SELECT 子查询 INSERT INTO 表?

2021-11-20 00:00:00 insert-into select subquery mysql

MySQL 如何使用返回多行的 SELECT 子查询 INSERT INTO 表?

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.

相关文章