How to update fields of table1/list1 with values from table2?

Status
Not open for further replies.
Hi,

I have a problem with update of my table1/list1,

table1 has fields:
id, login, name, email - and it has about 500records
for example:
48, jackb, Jack Blue, j.blue@candc.pl
I add some fields to table1: field11, field12, field13, ..., field20

Now i need update on table1 those : field11, field12, field13,..., field20 for all "about" 500 records -- with value from table2/list2.

table2/list2 has structure:
id, user_id, field_name, field_value
for example:
1, 48, field11, aaa_field11_value
2, 48, field12, bbb_field12_value
3, 49, field11, aaa_field11_value
4, 49, field20, kkk_field20_value

field_name has values: field11, field12, field13,..., field20
we should compare id.table1 with user_id.table2

I have a problem with SQL statue under phpmyadmin for each field11, field12, ...,field20
Can you help me to write right SQL for field11,
it should be something like this:

WHEN id.table1=user_id.table2 update field11.table1 with field_value.table2 WHERE field_name.table2=field11.table1

It is a bit to complicate for me... :-(

Is other way do the same under fabrik?
 
I assume this has only be done once?
I would do it "quick & dirty":
UPDATE table1 SET field11 = (SELECT field_value FROM table2 WHERE table1.id=table2.user_id AND table2.field_name='field11')

No warranty, update your tables before trying;)
 
Oh, many-many-thanks for this! This work like a charm. I am trying to improve my mysql query skils.:)

For this moment threat is solved.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top