•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 403,389 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 327 | Replies: 3
![]() |
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I've got two tables - members and sponsor, their simplified structure below.
members:
id_num
program_id
sponsor_program_id
sponsor:
id_num
sponsor
Some of the members in members table are sponsors. I need to update the field sponsor_program_id in all records in members table with their sponsors program_id field. Sponsor table tells me who their sponsor is, i.e. gives me their id_num back in members. So the contents of program_id of the sponsor goes into the sponsor_program_id of the person they sponsored.
I'm very new to this and I am lost! Can someone help?
members:
id_num
program_id
sponsor_program_id
sponsor:
id_num
sponsor
Some of the members in members table are sponsors. I need to update the field sponsor_program_id in all records in members table with their sponsors program_id field. Sponsor table tells me who their sponsor is, i.e. gives me their id_num back in members. So the contents of program_id of the sponsor goes into the sponsor_program_id of the person they sponsored.
I'm very new to this and I am lost! Can someone help?
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 239
mysql Syntax (Toggle Plain Text)
UPDATE members SET members.sponsor_program_id=sponser.program_id WHERE sponser.id_num=members.id_num;
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Here is some simplified sample data, maybe this will help.
members:
id_num = 1
program_id = 123
sponsor_program_id = 92
extra:
id_num = 1
sponsor = 0
members:
id_num = 2
program_id = 545
sponsor_program_id =
extra:
id_num = 2
sponsor = 1
Ok, so here are two members. id_num 1 & 2. id_num 1 is id_num 2's sponsor based on record in extra table. I need an sql statement that will update id_num 2's sponsor_program_id with id_num 1's program_id of 123
members:
id_num = 1
program_id = 123
sponsor_program_id = 92
extra:
id_num = 1
sponsor = 0
members:
id_num = 2
program_id = 545
sponsor_program_id =
extra:
id_num = 2
sponsor = 1
Ok, so here are two members. id_num 1 & 2. id_num 1 is id_num 2's sponsor based on record in extra table. I need an sql statement that will update id_num 2's sponsor_program_id with id_num 1's program_id of 123
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp database decimal seperator thousand seperator when using sql server deleting records from ms sql table where columns have duplicate values developer development hacker management studio 2005 microsoft msdn news office security software sql sql cache dependency with polling-based invalidation survey vista
- is there something wrong with my SQL statement? (PHP)
- Syntax error in "like" in sql statement (ASP.NET)
- Question about SQL statement (MS SQL)
- SQL statement error (ASP.NET)
- sql statement (Visual Basic 4 / 5 / 6)
- run sql statement in asp (ASP)
Other Threads in the MySQL Forum
- Previous Thread: php/mysql dynamic multi-level menu problem
- Next Thread: joining c variable with mysql



Linear Mode