Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Update Statement w/2 Primary Keys

Update Statement w/2 Primary Keys

Update Statement w/2 Primary Keys

member table contains:
member.member_id (PRIMARY)

member_product table contains:
member_product.member_id (PRIMARY)
member_product.product_type_id (PRIMARY)

related_to contains the member_id of the parent company.  If there is no parent company, it contains the model_id of itself.

Whenever I receive a signed form, I manually go into the member_product table and change the form_received field to 'true' for the parent company.

My goal is to develop a statement that can be run afterwards to update all the subsidiary companies.

The problem is the double primary key in member_product. A member_id can have several product_type_id so both are needed for uniqueness.

The logic I'm using goes:
1 - search member_product to find where form_received is not null and record member_id and product_type_id.
2 - use member_product.member_id collected as member.related_to and collect the resulting list of subsidiary companies by recording the returned member.member_id
3 - take member.member_id back into member_product table and update form_received to match the parent company's value BUT only for the correct product_type_id in step 1.

I can't figure out a way to ensure it uses both primary keys and doesn't ignore one to screw up the data.  I've tried all day and only have a nice INNER JOIN statement that will get me the data I need.  I think there's a way to use it to automatically loop update statements but I'm not positive.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close