我有兩個表是在結構上是相同的。 Table1
持有主持人數據,table2
認爲仍未緩和數據。更新在兩個不同的表的列具有一個SQL
表1
+------+-----------+-----------------+--------+-----------+----------+ | "id" | "name" | "description" | "type" | "country" | "status" | +------+-----------+-----------------+--------+-----------+----------+ | "1" | "Title 1" | "Description 1" | "1" | "US" | "0" | | "2" | "Title 2" | "Description 2" | "1 " | "UK" | "0" | +------+-----------+-----------------+--------+-----------+----------+
表2
+------+-----------+-----------------+--------+-----------+----------+ | "id" | "name" | "description" | "type" | "country" | "status" | +------+-----------+-----------------+--------+-----------+----------+ | "1" | "Title 1" | "Description 1" | "1" | "US" | "2" | | "2" | "Title 2" | "Description 2" | "1 " | "UK" | "2" | +------+-----------+-----------------+--------+-----------+----------+
我試圖在兩者使用單個SQL表來更新列status
。其實,主持人只更新table2
因爲這是提供給他的表。
當table2
2得到更新,可以table1
可以在同一時間更新?使用單個sql?現在,我爲此使用了2個不同的convetional sql語句。
現在我這樣做:
UPDATE table2 set status = 0 where id = spid and country = spcountry;//Update table2 first
UPDATE table1 a
INNER JOIN table2 b
ON a.id = b.id and a.country = b.country
SET a.status = b.status
WHERE a.id=spid;
我希望做什麼:例
$status = 0;//php
update table1, table2 set status = $status where id=1 and conuntry = 'us' in table1 and table2.//The id and country need to be the same in both tables.
重複的問題:http://stackoverflow.com/questions/2044467/how-to-update-two-tables-in-one-statement-in-sql-server-2005 –
這個副本是mysql:http:/ /stackoverflow.com/questions/8765490/mysql-update-two-tables-at-once –
爲什麼你只想使用1個SQL? – Raptor