-
December 8th, 2010, 09:32 AM
#1
HELP with 2 different mysql table
im trying to grab data from a user table on one db and move it to another db with different table columns
i have this layout
This is wanted result
now field ID will be same for all rows....userid will obv be different
| ID | userID | fieldID | Value |
--------------------------------------------------------
| 1 | 62 | 2 | Male |
This is old table that i need to pull the info
| userID | Gender |
----------------------------
| 62 | 1 |
what is the synt i would use?
Last edited by davidjmorin; December 8th, 2010 at 09:37 AM.
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
December 12th, 2010, 07:39 AM
#2
Re: HELP with 2 different mysql table
not tested but I think this should work
Code:
INSERT INTO
db2.table2(userID, gender)
VALUES
((
SELECT userID, fieldID
FROM db1table1
))
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 12th, 2010, 08:44 AM
#3
Re: HELP with 2 different mysql table
Thank you for your reply
if you notice though in on db the gender is "male" but in the new one it is "1"
How would that work?
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
December 12th, 2010, 08:49 AM
#4
Re: HELP with 2 different mysql table
Originally Posted by davidjmorin
if you notice though in on db the gender is "male" but in the new one it is "1"
right, I didn't notice that
Originally Posted by davidjmorin
How would that work?
I think this will do
Code:
IF(condition, value_if_condition_true, value_if_condition_false)
Code:
INSERT INTO
db2.table2(userID, gender)
VALUES
((
SELECT userID, IF(Value = "Male", 1, 2) as gender
FROM db1.table1
))
though I'm not certain if there should be a single or double "="
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 12th, 2010, 08:54 AM
#5
Re: HELP with 2 different mysql table
great.... that worked... thank you so mcuh
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|