User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Feb 2008
Posts: 2
Reputation: tangosdad is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tangosdad tangosdad is offline Offline
Newbie Poster

Help with SQL Statement Please

  #1  
Feb 8th, 2008
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Help with SQL Statement Please

  #2  
Feb 8th, 2008
  1. UPDATE members SET members.sponsor_program_id=sponser.program_id WHERE sponser.id_num=members.id_num;
This will update the members by setting sponser_program_id to the program_id of sponser when id_num of sponser is equal to id_num of members.
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*
Reply With Quote  
Join Date: Jan 2008
Posts: 9
Reputation: Jake Kittell is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Jake Kittell Jake Kittell is offline Offline
Newbie Poster

Re: Help with SQL Statement Please

  #3  
Feb 9th, 2008
Perhaps you could give an example to more clearly illustrate what you are trying to do?
Jake
Reply With Quote  
Join Date: Feb 2008
Posts: 2
Reputation: tangosdad is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tangosdad tangosdad is offline Offline
Newbie Poster

Re: Help with SQL Statement Please

  #4  
Feb 9th, 2008
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC