我有两张桌子:rec_new_license和recruit_zips。
recruit_zips包含' zip_code'和' office_name'并包含邮政编码和办公室名称。
rec_new_license包含一个字段' zip'和一个字段' recruit_office'。 这张桌子需要有一个" recruit_office'字段更新,如果' zip'中的值匹配' zip_code'在recruit_zips表和' office_name'匹配' Spring Hill'。
任何查询都不会执行任务或因错误而失败。我错了吗?
$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'
";
答案 0 :(得分:0)
你的语法错了。必须是:
$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'
";