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

Posted on 2007-10-01
Last Modified: 2012-06-22
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
Question by:adworldmedia
    1 Comment
    LVL 142

    Accepted Solution

    UPDATE logins
     SET affiliateid = ar.ID
    FROM logins l
    JOIN affiliaterecords ar
      ON =

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
    In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now