日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ERROR 1093 解决方法

發布時間:2024/4/14 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ERROR 1093 解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對于這個錯誤信息:

ERROR 1093 (HY000): You can't specify target table 'clients' for update in FROM clause

或者:

ERROR 1093 (HY000): You can't specify target table 'clients' for delete in FROM clause



一直以來我以為只有一種辦法。不過今天翻開以前的書,發現還有一個方法。

表結構和示例數據:

mysql> show create table branches\G

*************************** 1. row ***************************

?????? Table: branches

Create Table: CREATE TABLE `branches` (

? `bid` int(11) NOT NULL,

? `cid` int(11) NOT NULL,

? `bdesc` varchar(1000) NOT NULL,

? `bloc` char(2) NOT NULL,

? PRIMARY KEY (`bid`),

? KEY `cid` (`cid`),

? CONSTRAINT `branches_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `clients` (`cid`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.00 sec)


mysql> select * from branches;

+------+-----+--------------------------------+------+

| bid? | cid | bdesc????????????????????????? | bloc |

+------+-----+--------------------------------+------+

| 1011 | 101 | Corporate HQ?????????????????? | CA?? |

| 1012 | 101 | Accounting Department????????? | NY?? |

| 1013 | 101 | Customer Grievances Department | KA?? |

| 1031 | 103 | N Region HO??????????????????? | ME?? |

| 1032 | 103 | NE Region HO?????????????????? | CT?? |

| 1033 | 103 | NW Region HO?????????????????? | NY?? |

| 1041 | 104 | Branch Office (East)?????????? | MA?? |

| 1042 | 104 | Branch Office (West)?????????? | CA?? |

| 1101 | 110 | Head Office??????????????????? | CA?? |

+------+-----+--------------------------------+------+

9 rows in set (0.00 sec)

mysql> show create table clients\G

*************************** 1. row ***************************

?????? Table: clients

Create Table: CREATE TABLE `clients` (

? `cid` int(11) NOT NULL,

? `cname` varchar(64) NOT NULL,

? PRIMARY KEY (`cid`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

mysql> select * from clients;

+-----+-----------------------------+

| cid | cname?????????????????????? |

+-----+-----------------------------+

| 101 | JV Real Estate????????????? |

| 102 | ABC Talent Agency?????????? |

| 103 | DMW Trading???????????????? |

| 104 | Rabbit Foods Inc??????????? |

| 110 | Sharp Eyes Detective Agency |

+-----+-----------------------------+

5 rows in set (0.00 sec)


mysql> delete from clients where cid = (select clients.cid from clients left join branches using(cid) where bid is null);

ERROR 1093 (HY000): You can't specify target table 'clients' for update in FROM

clause


解決辦法

1、利用變量賦值。

mysql> select @m_cid:=clients.cid from clients left join branches using(cid) where bid is null;

+---------------------+

| @m_cid:=clients.cid |

+---------------------+

|???????????????? 102 |

+---------------------+

1 row in set (0.00 sec)

mysql> delete from clients where cid = 102;

Query OK, 1 row affected (0.05 sec)


mysql> select * from clients;

+-----+-----------------------------+

| cid | cname?????????????????????? |

+-----+-----------------------------+

| 101 | JV Real Estate????????????? |

| 103 | DMW Trading???????????????? |

| 104 | Rabbit Foods Inc??????????? |

| 110 | Sharp Eyes Detective Agency |

+-----+-----------------------------+

4 rows in set (0.00 sec)


2、用EXISTS關鍵字和相關子查詢:(不過這個沒有之前的效率高)

mysql> insert into clients values(102,'ABC Talent Agency');

Query OK, 1 row affected (0.05 sec)


mysql> delete from clients where not exists

??? -> (

??? -> select * from branches where branches.cid = clients.cid

??? -> );

Query OK, 1 row affected (0.06 sec)


mysql> select * from clients;

+-----+-----------------------------+

| cid | cname?????????????????????? |

+-----+-----------------------------+

| 101 | JV Real Estate????????????? |

| 103 | DMW Trading???????????????? |

| 104 | Rabbit Foods Inc??????????? |

| 110 | Sharp Eyes Detective Agency |

+-----+-----------------------------+

4 rows in set (0.00 sec)

轉載于:https://blog.51cto.com/wyfirst/195882

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的ERROR 1093 解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。