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)