Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    23

    Question Unanswered: INSERT from two tables

    Good evening,

    I'm trying to insert Fiscal Year from one table and unique ID from another table joined by Employee Number. Anyone know how to make it work?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Like this:
    Code:
    INSERT INTO DestinationTable ( [Fiscal Year], [unique ID] )
    SELECT SourceTable1.[Fiscal Year], SourceTable2.[unique ID] 
    FROM SourceTable1 INNER JOIN 
         SourceTable2 ON SourceTable1.[Employee Number] = SourceTable2.[Employee Number];
    Use a LEFT JOIN if you want to keep Null values for the rows (if any) where there is no match for [Employee Number] between both table.

    Note: You should refrain from using spaces (or other non-alphanumeric characters as well as reserved words) in the names and replace them with an underscore:
    "Fiscal_Year" instead of "Fiscal Year"
    Have a nice day!

  3. #3
    Join Date
    Jan 2012
    Posts
    23
    INNER JOIN works amazing.

    Thanks Sinndho!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •