Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.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 如果值位于“从其他表中选择”中,则更新表_Mysql - Fatal编程技术网

Mysql 如果值位于“从其他表中选择”中,则更新表

Mysql 如果值位于“从其他表中选择”中,则更新表,mysql,Mysql,我有两张表:rec_new_license和recruit_zips 招聘拉链包含“邮政编码”和“办公室名称”,并包含邮政编码和办公室名称 rec_new_许可证包含一个字段“zip”和一个字段“recruit_office”。 如果'zip'中的值与recruit_zips表中的'zip_code'匹配,并且'office_name'与'Spring Hill'匹配,则此表需要更新'recruit_office'字段 这两个查询都不会执行任务,也不会因错误而失败。我做错了吗 $sql = "U

我有两张表:rec_new_license和recruit_zips

招聘拉链包含“邮政编码”和“办公室名称”,并包含邮政编码和办公室名称

rec_new_许可证包含一个字段“zip”和一个字段“recruit_office”。 如果'zip'中的值与recruit_zips表中的'zip_code'匹配,并且'office_name'与'Spring Hill'匹配,则此表需要更新'recruit_office'字段

这两个查询都不会执行任务,也不会因错误而失败。我做错了吗

$sql = "UPDATE rec_new_license 
SET recruit_office = 'Spring Hill' 
WHERE zip IN 
( 
 SELECT zip_code FROM recruit_zips 
 WHERE office_name = 'Spring Hill'
)";

$results = $mysqli->query($sql);
还尝试:

$sql = "UPDATE rec_new_license t1
  JOIN recruit_zips t2
    ON t1.zip = t2.zip_code
    WHERE t2.office_name = 'Spring Hill'
SET t1.recruit_office = 'Spring Hill'
";

你的语法错了。它必须是:

$sql = "UPDATE rec_new_license t1
  JOIN recruit_zips t2
    ON t1.zip = t2.zip_code
    SET t1.recruit_office = 'Spring Hill'
    WHERE t2.office_name = 'Spring Hill'
";

成功了。还需要添加:ON t1.zip COLLATE utf8\u unicode\u ci=t2.zip\u代码谢谢!