Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL,将值作为select语句的Insert语句_Mysql_Database_Select_Insert - Fatal编程技术网

MySQL,将值作为select语句的Insert语句

MySQL,将值作为select语句的Insert语句,mysql,database,select,insert,Mysql,Database,Select,Insert,我正在尝试将值作为insert语句插入此表。我想我只是使用了错误的语法。有什么帮助吗?值仅在插入文字记录时使用。相反,只需插入包含两个子查询的select语句: insert into class_pre_req(class_id, cpr_id) values(select class_id from classes where catlg_nbr = 265 and subject_id = 27, select class_id from classes where catlg_nbr =

我正在尝试将值作为insert语句插入此表。我想我只是使用了错误的语法。有什么帮助吗?

值仅在插入文字记录时使用。相反,只需插入包含两个子查询的select语句:

insert into class_pre_req(class_id, cpr_id) values(select class_id from classes where catlg_nbr = 265 and subject_id = 27, select class_id from classes where catlg_nbr = 166 and subject_id = 27);
请注意,为了使其工作,每个子查询必须返回一个值

INSERT INTO class_pre_req (class_id, cpr_id)
SELECT
    (SELECT class_id FROM classes WHERE catlg_nbr = 265 AND subject_id = 27),
    (SELECT class_id FROM classes WHERE catlg_nbr = 166 AND subject_id = 27);