mysql - Copy values from one field to another within a subset -


i'm trying create query i'm stuck.

context on website users have different fields on profile. 1 of these fields checkbox newsletter. going make second newsletter. every user subscribed newsletter automatically subscribed second , have option unsubscribe. user not subscribed original newsletter should not receive second newsletter either.

table fields stored in table "profile_field". table has 3 columns

  • fid => field id (this can profile name, address, newsletter, ...)
  • uid => user id
  • value

so every user need copy value of field1 field2

the query far

update profile_values copy set value =    (select value     ( select value            profile_values original            fid = 12          ) temp    ) fid=37 ; 

now gives me error:

error 1242 (21000): subquery returns more 1 row

i understand why have this. it's because in subquery don't take account field returns multiple results because of different users. in other words don't take user account.

so tried like

from ( select value            profile_values original            fid = 12          ) temp uid=copy.uid 

but doesn't work either.

error 1064 (42000): have error in sql syntax; check manual corresponds mysql server version right syntax use near '"temp" uid=copy.uid )where fid=37' @ line 1

so how can take user account in query?

warm regards

stephan celis

for update use:

update profile_values pv        join (select value,                     uid                profile_values               fid = 12) current_field_values          on current_field_values.uid = pv.uid set    pv.value = current_field_values.value  pv.fid = 37   

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -