INSERT Into 中的第二个子查询保存 int 0

Second Subquery Inside INSERT Into saves int 0

仔细阅读,我们有这个查询,它在名为 users 的 table 中插入值。对于值 member_id,我们是 运行 从 table admin_users 成员 ID 到 select 的子查询。之所以有single quotes+,是因为我们试图操纵查询。此时第一个子查询工作正常,但是第二个子查询发生了什么?

第二个子查询 selects pass 来自 table settings,table settings 和值 pass 完全存在并且只有一条记录,但是 INSERT INTO 中的第二个查询没有返回任何内容。当查询 INSERT INTO 的执行完成时,所有值都被正确存储,除了最终插入 0 的注释列。我不知道为什么但是如果你删除所有 ''+ 它整个 sql 语句,但此时我们不能删除 ''+,因为我们正在更改查询。我需要这个问题的解决方案。

INSERT INTO `users` (`username`,`password`,`number`,`member_id`,`exp_date`,`notes`) VALUES ('balvin','sjeneoeoe','3',''+(select id from `admin_users` where username = 'TEST')+'','1644622354','' + (select pass from `settings`));#;');

我也试过像这样修改第二个子查询,但没有成功。

'' + (select pass from `settings` LIMIT 1)
'' + (select pass from `settings` GROUP BY pass LIMIT 1)
'' + (select pass from `settings` where id = 1 LIMIT 1)

可能是设置中传递的列值的数据类型或用户中的列注释的错误

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `member_id` int(11) DEFAULT NULL,
  `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `exp_date` int(11) DEFAULT NULL,
  `notes` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `number` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `member_id` (`member_id`),
  KEY `exp_date` (`exp_date`),
  KEY `username` (`username`),
  KEY `password` (`password`),
) ENGINE=InnoDB AUTO_INCREMENT=1702894 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

    
CREATE TABLE `settings` (
  `id` int(11) NOT NULL,
  `name` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `pass` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

将您的插页写成 select,而不是 values

未经测试,但类似于:

INSERT INTO `users` (`username`,`password`,`number`,`member_id`,`exp_date`,`notes`) 
select 'balvin','sjeneoeoe','3', 
  (select id from `admin_users` where username = 'TEST'),
  '1644622354', 
  (select pass from `settings`);

注意每个 sub-query 必须 return 一行。