[英]mysql procedure : Result consisted of more than one row with select statement
我正在为我的常规重复工作创建一个程序。
其中,将一个表中的多行插入到临时表中有一个步骤。
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
但它给了我错误:结果包含多于一行
正确的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.