There are times when we need to update data from multiple tables and then we need to use the following methods:
(1) SQLite multiple table Update method
Copy Code code as follows:
//----------------------------------
Update T1 set Col1=t2.col1
from table1 t1
Inner JOIN table2 T2 on T1.col2=t2.col2
This is a very simple batch update statement that is supported in SQL Server for this syntax SQLite but does not support
SQLite can be converted to the following syntax
Copy Code code as follows:
Update table1 Set col1= (select col1 from table2 where col2=table1.col2)
Update Ta_jbnt_tzhd_pht_area_xiang Set t1= (select Sys_xzqhdm.name from SYS_XZQHDM
where T2=sys_xzqhdm.code)
(2) SQL Server multiple table Update method
Copy Code code as follows:
//----------------------------------
SQL Server syntax: UPDATE {table_name with (< table_hint_limited > [... n]) |
view_name | rowset_function_limited} SET {column_name = {expression | DEFAULT
| NULL} | @variable = Expression | @variable = column = expression} [,... N]
{{[From {< Table_source >} [,... n]] [WHERE < search_condition >]} | [
WHERE Current of {{[GLOBAL] cursor_name} | cursor_variable_name}]} [
OPTION (< query_hint > [,... n])]
SQL Server Example:
Copy Code code as follows:
Update a set A.gqdltks=b.gqdltks,a.bztks=b.bztks from
Landleveldata A,GDQLPJ b where a.geo_code=b.lxqdm
Access database Multi-table Update method
Copy Code code as follows:
x = "Update" + DLTB + "A INNER join TBAREA2 B on A.objectid=b.fid set a." + FD_DLTB_XZDWMJ + "=B.AREA_XZDW, A." + Fd_d LTB_LXDWMJ + "=B.AREA_LXDW";
Sqllist.add (x);
(3) Oracle Multi-Table Update method
Oracle Syntax:
Copy Code code as follows:
UPDATE updatedtable SET (col_name1[,col_name2 ...]) = (SELECT
Col_name1,[,col_name2 ...] From srctable [WHERE where_definition])
Oracel Example:
Copy Code code as follows:
Update Landleveldata a set (A.gqdltks, A.bztks) = (select B.gqdltks,
B.bztks from GDQLPJ b where A.GEO_CODE=B.LXQDM)
(4) MySQL multiple table Update method
MySQL Syntax:
Copy Code code as follows:
UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE Where_definition]
MySQL Example:
Copy Code code as follows:
Update Landleveldata A, GDQLPJ b set a.gqdltks= b.gqdltks, a.bztks=
B.bztks where A.GEO_CODE=B.LXQDM