Insert data into a table from another table

  • I have two tables as follow:

    Table: Addresses

    AddressIDAddress1 Address2

    1123 West St Santa Ana, CA 92703

    224 Cantera New York, NY 10017

    532 Clinton Fountain, CA 92708

    7124 Edwards Las Vegas, NV 25478

    10417 Fontana[ Irvine, CA 92478

    Table: Sales

    SaleIDAddressIDAddress1Address2

    212

    225

    237

    I want to fill the Address1 and Address2 columns of the Sales table with the matching AddressID from the Addresses table. What is the SQL syntax? I am using SQL Server 2005. Thanks.

  • "JOIN" is what u are after 🙂

  • Can you be more specific? Please note that I want to actually fill the data into the table, not just "join" the two tables for an output. Thanks

  • There are a couple ways to do what you are looking for, here is one:

    UPDATE S

    SET

    Address1 = A.Address1,

    Address2 = A.Address2

    FROM Sales S

    INNER JOIN Addresses A

    ON S.AddressID = A.AddressID;

    Of course I have no idea why you would want to duplicate the address information...

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply