
Answer-first summary for fast verification
Answer: Use MERGE to conditionally insert or update records.
MERGE INTO in Delta Lake allows you to conditionally insert, update, or delete records based on a matching condition between the source and target tables. For example: ```sql MERGE INTO target_table AS t USING source_table AS s ON t.id = s.id WHEN NOT MATCHED THEN INSERT * ``` Reference: From the Databricks documentation on MERGE INTO: https://docs.databricks.com/aws/en/delta/merge#data-deduplication-when-writing-into-delta-tables The MERGE INTO statement allows you to merge a set of updates, insertions, and deletions into a Delta table based on a source table. This is useful for deduplication and upserts.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Given a scenario where you need to load data from an external source into a Delta Lake table, but the data might contain duplicates that should not be written to the table. Which SQL command would you use to ensure that only new, non-duplicate records are added to the table?
A
Use CREATE OR REPLACE TABLE to replace the entire table with new data.
B
Use INSERT OVERWRITE to selectively overwrite partitions.
C
Use MERGE to conditionally insert or update records.
D
Use COPY INTO to load data from external sources without duplication.
No comments yet.