Hi,
I am have a MySQL database and need to insert/update a table (T3) using data from two other tables (T1 & T2).
T3 should have 2 columns (PID & Name) which match 2 columns in T1, with additional columns based on the row values of T2. A simple "insert" can add the rows from T1 to T3 for matching columns, but the problem I am having is getting T2 data into T3.
T2 essentially has 3 columns (PID, Field, Data). The PID matches the PIDs in T1, the Field is a variable of about 15 different field identifiers, and the Data is the value for that Field for that PID. What I need to do is add the Field values as column names in T3 (so T3 would end up with 2 + 15 columns) and then update the row value of each Column according to the Data value matchin the PIC in T2. Here is a simplified graphical representation:
----- T1 -------
PID Name
1 Bob
2 Jerry
3 Jane
----------------
---- T2 -----------------------
PID Field Data
1 Address 1 address
1 Phone 111111111
1 Website
www.a.com
2 Phone 222222222
2 Address 2 address
3 Address 3 address
3 Website
www.b.com
------------------------------------------
Need to combine these into T3 table:
------------------ T3 -------------------------------------
PID Name Address Phone Website
1 Bob 1 address 11111111
www.a.com
2 Jerry 2 address 22222222
3 Jane 3 address
www.b.com
-----------------------------------------------------------
As there are limited "Field" types in T2, I could set up the columns in T3 first if necessary.
I would be grateful for any help on this.
Regards, Richard.