1. 程式人生 > >MySQL 中 You can't specify target table '表名' for update in FROM clause錯誤解決辦法

MySQL 中 You can't specify target table '表名' for update in FROM clause錯誤解決辦法

在MySQL中,寫SQL語句的時候 ,可能會遇到You can't specify target table '表名' for update in FROM clause這樣的錯誤,它的意思是說,不能先select出同一表中的某些值,再update這個表(在同一語句中),即不能依據某欄位值做判斷再來更新某欄位的值。

1、資料準備

product表資料如下:


laptop表資料如下:

2、要求:#刪除所有不生產印表機廠商生產的膝上型電腦

第一步:對aptop表進行操作

操作沒有問題,按照本思路對product表進行操作

產生You can't specify target table '表名' for update in FROM clause錯誤

3、問題解決

將SELECT出的結果再通過中間表SELECT一遍,這樣就規避了錯誤。

需要注意的是,這個問題只出現於MySQL,MSSQL和Oracle不會出現此問題。

相關推薦

MySQL You can't specify target table '' for update in FROM clause錯誤解決辦法

在MySQL中,寫SQL語句的時候 ,可能會遇到You can't specify target table '表名' for update in FROM clause這樣的錯誤,它的意思是說,不能先select出同一表中的某些值,再update這個表(在同一語句中),即

MySQL You can't specify target table '' for update in FROM clause錯誤

在MySQL中,寫SQL語句的時候 ,可能會遇到You can't specify target table '表名' for update in FROM clause這樣的錯誤,它的意思是說,不能先select出同一表中的某些值,再更新這個表(在同一語句中),即不能依據某

MYSQLYou can't specify target table for update in FROM clause解決辦法

這篇文章主要介紹了mysql中You can’t specify target table for update in FROM clause錯誤解決方法,需要的朋友可以參考下 mysql中You can't specify target table for update

MySQL 出現You can't specify target table for update in FROM clause

MySQL出現You can’t specify target table for update in FROM clause 這個錯誤的意思是不能在同一個sql語句中,先select同一個表的某些值,然後再update這個表。 例如:message表儲存了多個使用者的訊息 建立表 CREATE TABLE

按條件刪除記錄時報You cant specify target table for update in FROM clause錯誤解決方法(寫於20161107)

核心概念:     mysql中,不能先select一個表的記錄,在按此條件進行更新和刪除同一個表的記錄。解決辦法是,將select得到的結果,再通過中間表select一遍,這樣就規避了錯誤,這個問題只出現於mysql,mssql和oracle不會出現此問題。自己例項一:如下業務場景,ecs_order_sh

關於mysql 5.7版本“報[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause錯誤的bug

title _id fma xxx tps ice sql each targe 不同於oracle和sqlserver,mysql並不支持在更新某個表的數據時又查詢了它,而查詢的數據又做了更新的條件,因此我們需要使用如下的語句繞過: UPDATE teaching_de

MySQL 錯誤碼: 1093 You can't specify target table 'jc_user' for update in FROM clause

MySQL 錯誤碼: 1093 You can’t specify target table ‘jc_user’ for update in FROM clause bug如何出現及解決方案 根據錯誤資訊可知:不能查詢一張表的同時修改同一張表

MySQL:You cant specify target table ‘A’ for update in FROM clause

按照MYSQL5.0文件的解釋:我們不能在修改表A的同時在其子查詢中使用到表A,但是可以通過在子查詢中在巢狀一層針對表A的子查詢,因為最裡層的子查詢產生的結果存在臨時表中,與表A沒有關係。 解決方法:把類似於 UPDATE t ... WHERE col = (SELE

錯誤You can't specify target table 'xxx' for update in FROM clause解決

參考:https://www.cnblogs.com/pcheng/p/4950383.html   解決:   程式碼: <!-- 執行"取消收藏" 操作 -> 根據前端傳入的商品id和sessio

如何解決You cant specify target table for update in FROM clause錯誤

mysql中You can’t specify target table for update in FROM clause錯誤的意思是說,不能先select出同一表中的某些值,再update這個表(在同一語句中)。 例如下面這個sql:delete from target_info_day where id

MySQLYou can't specify target table for update in FROM clause

問題:You can't specify target table for update in FROM clause 含義:不能在同一表中查詢的資料作為同一表的更新資料。 注意:這個問題只出現於mysql,mssql和oracle不會出現此問題。 delete from people wher

mysql修改刪除You can't specify target table for update in FROM clause的問題

you div code sql 語句 操作 查詢 重復數 -c sele 表中出現重復數據,需要刪除重復數據,只保留一條 DELETE FROM crm_participant WHERE id IN ( SELECT c.id cid F

updateupdate無法用基於被更新的子查詢,You can't specify target table 'test1' for update in FROM clause.

子查詢 src nbsp spec tab can 技術分享 例如 bubuko update中無法用基於被更新表的子查詢,You can‘t specify target table ‘test1‘ for update in FROM clause. 情況如下: (

You can't specify target table 't_mail_marketing' for update in FROM clause

update in table use pre RKE can stat mail date update t_mail_marketing set `STATUS` = 1 where ID in ( select b.PARENT_ID from (SELECT D

You can't specify target table 'table' for update in FROM clause

tar bsp stock select CA HA lec pan having delete from table1 where ID not in(select max(ID) ID from table1 group by row1) and row1 in

[Err] 1093 - You can't specify target table 'master_data' for update in FROM clause

sel master mce 沒有 AR delete 查詢 數據 select delete from master_data where category_id not in (select category_id from master_data a, bc_cate

You can't specify target table 't_open_user' for update in FROM clause

https://blog.csdn.net/jiangyu1013/article/details/79108498 報錯如題,意思大致是:在一條 sql 語句中不能先查出來部分內容,再同時又對當前表作修改。 解決方法:給查詢加別名,用中間表來實現不是對同一表作操作。 如錯誤定法

[Err] 1093 - You can't specify target table 's1_test' for update in FROM clause

前提說明:資料庫採用的是mysql。 資料庫表格: 題目: 刪除除了編號不同,其他資訊都相同的冗餘資訊。 思路: 1.找出除了編號不同,其他資訊不全相同的編號。 關鍵詞:group by……having :分組查詢,我對這個關鍵詞的理解是:不同的行之間找出列相同的一項或者

mysql啟動報can't create/write to file 'var/run/mysqld/mysqld.pid 錯誤解決辦法

msql啟動報錯,啟動不了。 進入mysql日誌預設的路徑為 /var/log/mysqld.log 檢視日誌,發現報錯資訊如下: can't create/write to file 'var/run/mysqld/mysqld.pid 解決辦法: 將 /var/run/my

mysql 在修改新增欄位(alter table add column 或者 modify column)且帶unique時提示duplicate entry for key的原因以及解決方案

今天在公司臨時維護一張表時,我作了一個小動作,新增一個欄位,並且設定為unique時,盡然無法新增欄位,我當時就納悶了,寫了這麼多sql,這麼奇怪的問題還是第一次見,不多說,直接看圖 【我的sql檔案如下】 【執行sql語句報錯:alter table smart_