Posts

Showing posts with the label Education

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...

PostgreSQL ON CONFLICT Statement

PostgreSQL ON CONFLICT Statement - Explained PostgreSQL ON CONFLICT Statement - Explained ๐Ÿ“˜ Introduction to ON CONFLICT Statement In PostgreSQL, ON CONFLICT provides a powerful mechanism to deal with data clashes during INSERT operations. When inserting into a table that contains a UNIQUE constraint or index, you can define how the database should react—either by updating the existing record or ignoring the new one. ๐Ÿงช Syntax Overview INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...) ON CONFLICT (conflict_target) DO UPDATE SET column1 = value1, column2 = value2, ...; conflict_target: typically the column(s) with a UNIQUE constraint (e.g., employee_id) DO UPDATE: specifies what should be updated DO NOTHING: skips the insertion if conflict occurs ...

Mysql Merge

Image
MySQL MERGE Concept & Alternatives Explained MySQL MERGE Concept & Alternatives MySQL MERGE is not directly supported as a single SQL command like in some other database systems (e.g. SQL Server or Oracle), but the concept can be implemented using a combination of INSERT , UPDATE , and DELETE statements. The MERGE approach is helpful for syncing two tables where data may need to be inserted, updated, or removed depending on conditions. When implemented manually, this requires crafting multiple SQL queries to simulate the behavior. Users should have SELECT, INSERT, DELETE , and UPDATE privileges on both tables used in the MERGE operation. ๐Ÿ”ง Three Logical Cases in a MERGE Operation Case 1 – INSERT If a row exists in the source table but not in the target table, use INSERT to add it to the target. Case 2 – DELETE If a row exists in the tar...