Programming
HR
Think About SQL MERGE in Terms of a RIGHT JOIN
['View All Posts Lukaseder', 'I Made Jooq']
Java, SQL and jOOQ.
-- The target table MERGE INTO book_to_book_store AS t -- The source table USING book_to_book_store_staging AS s -- The RIGHT JOIN predicate ON t.book_id = s.book_id AND t.name = s.name -- The actions for each row, based on RIGHT JOIN matching WHEN MATCHED THEN UPDATE SET stock = s.stock WHEN NOT MATCHED THEN INSERT (book_id, name, stock) VALUES (s.book_id, s.name, s.stock); As always with a RIGHT JOIN , every row from right side of the join is matched with a matching row from the left side of the join, or an empty row of NULL values, if there’s no such match.