我正在运行一个简单的MySQL查询来使用子查询进行更新。这是我写的查询
UPDATE (
SELECT IP2.ID, IP2.IP4, IP2.CLIENT FROM IP_ADDRESS IP2 WHERE IP2.V_NET = VNET_ID AND IP2.CLIENT IS NULL AND IP2.IP4 < (RANG_E - 1)
ORDER BY IP2.IP4, IP2.CLIENT LIMIT 1
)AS IP SET IP.CLIENT = C_ID; 运行后,我得到以下错误:
The target table IP2 of the UPDATE is not updatable我有一些与mysql - The target table of the UPDATE is not updatable和The target table of the UPDATE is not updatable相关的问题,但我没有得到明确的答案。
我有什么遗漏的吗?如何编写此查询?有什么帮助吗?
发布于 2017-11-30 22:59:25
如果你的表上有主键,你就是安全的。
看看这段肮脏的旅程:
Try it at SQL Fiddle
样表
create table t( a char(1), i int );
insert into t values
('a', 1),
('b', 2),
('c', 3),
('d', 4);通过pk更新
/* updating using double subquery, only way to use your same table */
update t
set a = 'z'
where i = (select i from (select * from t) t2 order by i desc limit 1);将其应用到您的环境中。
发布于 2017-11-30 23:04:36
UPDATE语句的格式如下:
UPDATE [table name]
SET [column name] = [new value]
(optional WHERE clauses)您在问题中编写的更新sql没有任何意义。使用正确的结构重写它。
https://stackoverflow.com/questions/47576155
复制相似问题