Merge stage data into master table
SQL
Hard
2 views
Problem Description
You have ProductsStage(product_id, name, price). Update existing Products and insert new ones in one MERGE statement.
Output Format
DML statement(s)
Sample Test Case
Input:
Products, ProductsStage
Constraints
Use MERGE pattern
Official Solution
MERGE INTO Products p USING ProductsStage s ON (p.product_id = s.product_id) WHEN MATCHED THEN UPDATE SET name = s.name, price = s.price WHEN NOT MATCHED THEN INSERT (product_id, name, price) VALUES (s.product_id, s.name, s.price);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!