mysql update select用法实例
mysql update select用法实例
mysql update select用法实例应该使用inner join,即:
UPDATE friends INNER JOIN users ON friends.friendid=users.userid SET friends.friendname=users.username
MySQL是通过临时表来实现FROM子句里面的嵌套查询,那么把嵌套查询装进另外一个嵌套查询里,可使FROM子句查询和保存都是在临时表里进行,然后间接地在外围查询被引用。
我们来看如下sql语句:
update apples
set price = (
select price from (
select * from apples
) as x
where variety = 'gala')
where variety = 'fuji';
继续来看如下两条实例
update a set a.xx= (select yy from b) where a.id = b.id ;
但是在mysql中,不能直接使用set select的结果,必须使用inner join:
update a inner join (select yy from b) c on a.id =b.id set a.xx = c.yy
如下一条经典Mysql update语句赋值嵌套select实例
update mem_player set `DataWarehouse`=(select `DataWarehouse` from (select * from mem_player) as b where `Pid`=100000)
注:更多精彩文章请关注三联编程教程栏目。