views:

27

answers:

1

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 (picture) 
   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?

+3  A: 

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?

Donnie
haha...I need to update. Thanks for catcing my confusion.
WmasterJ
Replaced with `UPDATE users2, profile_values SET users2.picture = profile_values.valueWHERE profile_values.uid = users2.uid AND profile_values.fid = 31;`
WmasterJ