-2

I have two tables.

One table is as follows: Table1:

id title view date
117 title1 10 21-12-10
120 title2 21 21-12-09
125 title3 40 21-12-08
127 title4 50 21-12-07
... ... ...

The other tables is as follows: Table2:

id view
117 1158
120 3257
... ...

Table 1 and Table 2 are joined based on id,

and Table 1 is to be updated.

However, since the size of table 1 is very large, I would like to table 1 select based on the date column.

Finally, I want to join the following two tables and update them.

id title view date
117 title1 10 21-12-10
120 title2 21 21-12-09
id view
117 1158
120 3257
... ...

After the update table1:

id title view date
117 title1 1158 21-12-10
120 title2 3257 21-12-09
125 title3 40 21-12-08
127 title4 50 21-12-07
... ... ...

Is there a way?

minholee
  • 1
  • 1
  • Can you clarify how you are trying to update Table1? Is it that you only want to update rows in Table1 where the `date` column meets a certain condition (such as equal to, less than, etc.). – Robin Zimmerman Dec 10 '21 at 05:13
  • edit my question – minholee Dec 10 '21 at 05:20
  • Does this answer your question? [SQL - UPDATE table after SELECT statement](https://stackoverflow.com/questions/70301019/sql-update-table-after-select-statement) – P.Salmon Dec 10 '21 at 08:04

1 Answers1

1
UPDATE T1
SET T1.View = T2.View
FROM Table1 T1 INNER JOIN TABLE2 T2 ON T1.Id = T2.Id
--You can include the where condition in this case Date
IamChandu
  • 355
  • 6
  • 18