February 23rd, 2013, 10:54 PM
Merging/Moving Column from T1 to T2
I am not a pro at MySql. Having spent last few days trying to make it work I think I may need a bit of help.
Two tables. Form submission date is in T1. T1 has 5 columns. T2 has 8 columns, and contains all other data. FormId column is common between the two tables. I need to move DateSubmitted column from T1 to T2 and then run SELECT query on resulting combined columns to display the data from now combined T1 & T2 tables. I cannot figure out how to move DateSubmitted column from T1 to T2 and then run SELECT query on resulting dataset. I tried UNION and JOIN suggestions I found here and on other forums but without success. Need help with constructing working query please!
SELECT query for T2:
FormId = 6
FieldName IN ('field1','field2','field3','field4','field5','field6')
ORDER BY SubmissionId ASC
and this was also suggested, it runs but DateSubmitted is not displaying:
FROM table2 t2 INNER JOIN
table1 t1 ON t2.FormId = t1.FormId
WHERE t2.FormId = 6 AND
t2.FieldName IN ('field1','field2','field3','field4','field5','DateSubmitted')
ORDER BY t2.SubmissionId
February 24th, 2013, 01:21 AM
A join is the correct approach.
Based on what you've said, your second query should produce the correct result I think. Are you sure the DateSubmitted column contains a value?
Also do you actually have a row in T2 with a field name of 'DateSubmitted'? I thought that value came from T1?
Post CREATE statements for your two tables.
February 24th, 2013, 09:15 AM
DateSubmitted in T1 has value, I can see date and time in every row.
DateSubmited is a column in T1, it does not exist in T2, which is the root of my problem as T2 has all of the other data I am after.
FormId FieldName FieldValue SubmissionId
6 Field1 Value1 1
6 Field2 Value2 2
6 Field3 Value3 3
6 Field4 Value4 4
6 Field5 Value5 5
6 Field6 Value6 6
February 24th, 2013, 10:17 AM
Issue is resolved. Thanks.