1,修改1列
update student s, city cset s.city_name = c.namewhere s.city_code = c.code;
2,修改多個(gè)列
update a, bset a.title=b.title, a.name=b.namewhere a.id=b.id
•子查詢
update student s set city_name = (select name from city where code = s.city_code);
oracle查詢報(bào)這個(gè)錯(cuò)誤:single-row subquery returns more than one row
怎么解決?
數(shù)據(jù)庫(kù)按照你的條件查詢有多個(gè)重復(fù)的數(shù)據(jù)。
例如:
UPDATE "SYS_ROLE" ASET A ."DEPT_ID" = ( SELECT c."id" FROM "his_department_info" c WHERE c."dept_name" = A ."ROLE_NAME"
如果以上sql語(yǔ)句報(bào)single-row subquery returns more than one row的錯(cuò)誤,說(shuō)明 c表”dept_name” 和A 表.”ROLE_NAME” 的這兩個(gè)字段 數(shù)據(jù)重復(fù)
總結(jié)
以上所述是小編給大家介紹的如何使用MySQL一個(gè)表中的字段更新另一個(gè)表中字段,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選