I have two tables Table 1
and Table 2
.
Shown in this picture
Table 1 is the master table.
I need to insert data to Table 2 from Table 1 based on the Sale Date. ProductID is the primary key in Table 2. For example, for product ID 100276408 in table 1, the most recent sale date is 11/4/2015; for product ID 100276409, the most recent sale date is 17/8/2014; fro product ID 100276400, the most recent sale date is 7/7/2016. I need to insert these three records in to Table 2 .The result I want is shown in the Table 2. How Do I do that in SQL server 2014? Thank you for your time and help.