开发者

How to use Insert .. select, with conditional vars from insert

开发者 https://www.devze.com 2022-12-31 09:00 出处:网络
I have two separate tables both with user id columns uid. I want to take a value from all users in one table and insert it into the correct row for the correct user in the other table.

I have two separate tables both with user id columns uid. I want to take a value from all users in one table and insert it into the correct row for the correct user in the other table.

INSERT INTO users2 (p开发者_Python百科icture) 
   SELECT pv.value 
   FROM profile_values as pv, users2 as u 
   WHERE pv.uid = u.uid 
   AND pv.fid = 31 
   AND users2.uid=u.uid;

But it's not working because i seem not to have access to users2.uid inside of the select statement.

How would I accomplish this?


You should be able to access your u alias for users2 fine. Direct access to users2 isn't possible because you're INSERTing into it, so the row doesn't actually exist yet. Do you want to do an insert or update?

0

精彩评论

暂无评论...
验证码 换一张
取 消