gpt4 book ai didi

mysql 程序 : Result consisted of more than one row with select statement

转载 作者:行者123 更新时间:2023-11-29 07:25:44 25 4
gpt4 key购买 nike

我正在为我的常规重复工作创建一个程序。

其中,有一个步骤可以将一个表中的多行插入到临时表中。

CREATE TABLE `tmpUserList` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_type` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`first_name` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`last_name` varchar(45) COLLATE utf8_unicode_ci NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

..... some more queries.


INSERT INTO tmpUserList (
SELECT id, user_type,first_name,last_name, from user where id in (usersId)
);


SELECT * FROM tmpUserList; // return the result

但它给我错误:Result consisted of more than one row

最佳答案

正确的 INSERT SELECT 语法:

INSERT INTO tmpUserList(id, user_type,first_name,last_name)
SELECT id, user_type,first_name,last_name
FROM user
WHERE id IN (usersId);

如果 usersId 包含多个值,您可以使用:

WHERE FIND_IN_SET(id, usersId);  -- table scan

相关:MySQL Prepared statements with a variable size variable list

关于mysql 程序 : Result consisted of more than one row with select statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53921890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com