MYSQL 插入查询不起作用显示错误 "Database_Exception [ 1241 ]: Operand should contain 1 column(s)"

标签 mysql

我尝试过 MySQL 插入查询,但该查询不起作用并显示错误“Database_Exception [1241]:操作数应包含 1 列”。

====>插入查询

INSERT INTO `notifications` (`message`, `selected_numbers`, `creation_date`, `update_date`, `message_date`)
     VALUES ('hello testing',
              ('32', '655', '203', '205', '204', '202', '12', '497', '123', '949', '77', '942', '937', '944', '953', '565', '652', '440', '826', '290', '20', '172', '23', '271', '648', '91', '89', '90', '450', '92', '31', '770', '766', '734', '776', '376', '403', '66', '977', '616', '65', '379', '323', '841', '745', '428', '544', '22', '831', '787'), 
              1498889053, 1498889053, '07/01/2017');

我尝试在传递数组值中插入单个记录。 但这个查询不起作用。

最佳答案

我猜您希望该列表的每个元素进入单独的行,而其他 4 列相同。如果是这样,您可以使用 insert 。 。 。选择并在子查询中生成行:

INSERT INTO `notifications` (`message`, `selected_numbers`, `creation_date`, `update_date`, `message_date`)
     SELECT 'hello testing', sn.selected_number,
            1498889053, 1498889053, '2017-07-01'
     FROM (SELECT '32' as selected_number UNION ALL
           SELECT '655' UNION ALL
           . . .
           SELECT '787'
          ) sn

关于MYSQL 插入查询不起作用显示错误 "Database_Exception [ 1241 ]: Operand should contain 1 column(s)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860155/

相关文章:

mysql - 合并数据,特定条件下除外

php - 如何使用组函数显示 COUNT 查询

sql - 从 MySQL 写入 CSV?

php - 存储其中包含 unicode 字符的字符串

mysql - 只获取具有相同 id 的列的一项

php - 使用 file_get_contents 将文件(图像)添加到数据库?

mysql - 重命名外键以适应表的上下文

mysql - 连接到现有数据库 - node.js

php - 通过mysql select查询填充下拉列表

php - 如何在php中将多个表结果添加到单个json中