之前用SqlServer , update语句对表进行更新:
update a set a.xx= (select yy from b) ; 是可以的
但是在mysql中,不能直接使用set select的结果,
UPDATE ecs_users_copy
SET `user_name` = (
SELECT
`identity_card`
FROM
ecs_users_copy
WHERE
LENGTH(identity_card) = 18
AND LENGTH(user_name) != 18
)
这是错误的做法!
必须使用inner join:
demo1
update a inner join (select table from b) c set a.id = a.id where a xxx
demo2
UPDATE ecs_users_copy as a
INNER JOIN (SELECT `identity_card`,`user_name` FROM ecs_users_copy) b
SET a.user_name = a.identity_card
WHERE
a.user_id =a.user_id and (LENGTH(a.identity_card) = 18
AND LENGTH(a.user_name) != 18)
用到的东西越多就越容易混淆~~
写了一个星期Java , 再写回 php
\Exception e
, 突然发现为什么会不行,原来是php的异常是有$的~~~ 而Java没有~~~