Posts

Showing posts with the label bigquery

BigQuery MERGE Statement – Explained

Image
BigQuery MERGE Statement – Explained with Syntax & Use Cases BigQuery MERGE Statement – Explained ๐Ÿ“˜ What is BigQuery MERGE? The MERGE statement in BigQuery allows you to conditionally INSERT , UPDATE , or DELETE rows in a target table based on matching rows from a source table. It’s ideal for data synchronization, staging table merges, and incremental updates. ๐Ÿ–ผ️ Thumbnail Preview ๐Ÿงช Syntax Overview MERGE target_table AS T USING source_table AS S ON T.id = S.id WHEN MATCHED THEN UPDATE SET T.name = S.name WHEN NOT MATCHED THEN INSERT (id, name) VALUES (S.id, S.name); ๐ŸŽฏ Example Use Case MERGE dataset.inventory AS I USING dataset.new_arrivals AS N ON I.product_id = N.product_id WHEN MATCHED THEN UPDATE SET I.quantity = I.quantity + N...