【本文出自:https://www.jb51.net/article/150323.htm】
這篇文章主要介紹了如何使用MySQL一個表中的字段更新另一個表中字段,需要的朋友可以參考下
1,修改1列
1
2
3
|
update
student s, city c
set
s.city_name = c.
name
where
s.city_code = c.code;
|
2,修改多個列
1
2
3
|
update
a, b
set
a.title=b.title, a.
name
=b.
name
where
a.id=b.id
|
•子查詢
1
|
update
student s
set
city_name = (
select
name
from
city
where
code = s.city_code);
|
oracle查詢報這個錯誤:single-row subquery returns more than one row
怎么解決?
數據庫按照你的條件查詢有多個重復的數據。
例如:
1
2
3
4
5
6
7
8
|
UPDATE
"SYS_ROLE"
A
SET
A .
"DEPT_ID"
= (
SELECT
c.
"id"
FROM
"his_department_info"
c
WHERE
c.
"dept_name"
= A .
"ROLE_NAME"
|
如果以上sql語句報single-row subquery returns more than one row的錯誤,說明 c表”dept_name” 和A 表.”ROLE_NAME” 的這兩個字段 數據重復
總結
以上所述是小編給大家介紹的如何使用MySQL一個表中的字段更新另一個表中字段,希望對大家有所幫助