MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 23rd, 2013, 09:54 PM
molsonbubba1 molsonbubba1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 11 molsonbubba1 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 h 21 m 13 sec
Reputation Power: 0
Cool 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:

SELECT
SubmissionId,
FieldName,
FieldValue
FROM
#__submission_values
WHERE
FormId = 6
AND
FieldName IN ('field1','field2','field3','field4','field5','field6')
ORDER BY SubmissionId ASC

and this was also suggested, it runs but DateSubmitted is not displaying:

SELECT t2.SubmissionId,
t2.FieldName,
t2.FieldValue,
t1.DateSubmitted
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

Thanks.

Reply With Quote
  #2  
Old February 24th, 2013, 12:21 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 7053
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.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old February 24th, 2013, 08:15 AM
molsonbubba1 molsonbubba1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 11 molsonbubba1 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 h 21 m 13 sec
Reputation Power: 0
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.

T1
DateSubmitted FormId
2013-02-01 6
2013-02-02 6
2013-02-03 6
2013-02-04 6
2013-02-05 6
2013-02-06 6

T2
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

Reply With Quote
  #4  
Old February 24th, 2013, 09:17 AM
molsonbubba1 molsonbubba1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 11 molsonbubba1 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 h 21 m 13 sec
Reputation Power: 0
Issue is resolved. Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Merging/Moving Tolumn from T1 to T2

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap