MYSQL 字段替换字段

来源:百度知道 编辑:UC知道 时间:2024/05/14 03:40:34
Phpmyadmin里执行
update yz_posts set yz_posts.author=yz_threads.author from yz_threads,yz_posts where yz_threads.tid=yz_posts.tid

但是返回#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from yz_threads,yz_posts where yz_threads.tid=yz_posts.tid' at line 1

MYSQL语法不一样?.求答案

update yz_posts y set y.author=(select y2.author from yz_threads y2 where y2.tid=y.tid );

想用yz_threads表的author替换yz_posts 表的同值tid下的author是吗?您写的这个语句MYSQL肯定是不认的!!想实现的话得写个简单的存储过程就OK!!!需要游标的啦!!然后调用(CALL)这个存储过程!!