To update a table with new rows from another table every day in SQL, you can use the INSERT INTO … SELECT statement. This statement will insert the data from the select statement into the specified table.

You can use a query like this to update the table:

INSERT INTO table1 (column1, column2, column3)
SELECT column1, column2, column3
FROM table2
WHERE date_column = CURDATE()

This query will insert the data from table2 where the date_column matches today’s date (CURDATE()) into table1.

You can also use the MERGE statement to update the table with new rows from another table every day in SQL, it allows you to insert new rows or update existing rows based on a condition.

MERGE INTO table1 AS t1
USING (SELECT * FROM table2 WHERE date_column = CURDATE()) AS t2
ON (t1.id = t2.id)
WHEN MATCHED THEN
UPDATE SET t1.column1 = t2.column1, t1.column2 = t2.column2
WHEN NOT MATCHED THEN
INSERT (id, column1, column2) VALUES (t2.id, t2.column1, t2.column2);

This query will insert new rows from table2 where the date_column matches today’s date (CURDATE()) into table1 and update rows if the id matches.

(Visited 24 times, 1 visits today)
Was this article helpful?
YesNo
Close Search Window