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)
注:更多精彩文章請關注幫客之家編程教程欄目。