我有两张桌子:表1 =大学,表2 =学校
我将university_id添加到表2中,我需要连接两个表.
如果表1中的university_name和表2中的名称相同,则从表1中获取id并将其替换为表2 university_id
我是sql的新手,所以如果你能解释那将是伟大的.我也试过以下但没有用!
select a.id,b.name from university as a
inner join school as b on a.university_name = b.name
UPDATE `school` SET `university_id` = a.id WHERE a.university_name = b.name
最佳答案 就像是
UPDATE school a
JOIN university b ON a.university_name = b.name
SET a.university_id = b.id
应该管用