• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13444
  • Last Modified:

T-SQL UPDATE QUERY - update table from another table based upon relationshp?

I'm storing affiliate records in a table ('affiliaterecords') on Microsoft SQL Server 2005, and each record generates a unique INT ID number that is used as the primary key.  Also a field named 'email'

I have another table called 'logins', which stores a login name, password, and related account ID's.

I want to run an UPDATE query that pulls (based upon a reltaionship with the e-mail address field) the affiliaterecord ID field and inserts it into the 'logins' table's column named 'affiliateid' based upon a match on the email address which is in each table....

I hope this makes sense!  Thanks
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
UPDATE logins
 SET affiliateid = ar.ID
FROM logins l
JOIN affiliaterecords ar
  ON ar.email = l.email
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now