Merge stage data into master table

Hard
2 views 23 Jan 2026
You have ProductsStage(product_id, name, price). Update existing Products and insert new ones in one MERGE statement....

Insert one row into Customers

Easy
2 views 23 Jan 2026
Insert a customer with id=101, name='Amit', city='Pune'....

Insert multiple rows at once

Easy
3 views 23 Jan 2026
Insert 3 departments in one statement....

Update a single row

Easy
3 views 23 Jan 2026
Update customer city to 'Delhi' where customer_id=101....

Delete using a condition

Easy
2 views 23 Jan 2026
Delete orders where status='CANCELLED' and the order_date is older than 90 days from today....

Insert using SELECT

Easy
3 views 23 Jan 2026
Create a backup table OrdersBackup and copy only last month's orders into it (full rows)....

Update using a join

Medium
2 views 23 Jan 2026
Give 10% hike to Employees in department 'Tech'. Departments table has dept_name....

Delete duplicates keeping the latest

Medium
3 views 23 Jan 2026
In LoginLogs(user_id, logged_at, ip_address), remove duplicates where same user_id and ip_address appear multiple times on same day; keep the latest logged_at....

Upsert order status

Medium
2 views 23 Jan 2026
If an order exists update its status, otherwise insert it. Write an upsert pattern....

Insert into two tables with transaction

Medium
2 views 23 Jan 2026
Place an order and its order items together. If item insert fails, order should not be created....

Update based on subquery aggregate

Hard
2 views 23 Jan 2026
Give a 5% discount on Products that have not sold in the last 180 days. Use Orders + OrderItems to find what sold recently....

Soft delete pattern

Hard
3 views 23 Jan 2026
Instead of deleting customers, keep the row and mark it inactive. Add is_active (default 1) and set is_active=0 for customers who have no orders in the last 2 years....

Fix data using CASE

Hard
2 views 23 Jan 2026
In Employees, if salary is null set to 25000, if salary < 15000 set to 15000, else keep as is. Write one update statement....

Delete with correlated EXISTS

Hard
2 views 23 Jan 2026
Delete orders that have no order items (orphan orders)....

Bulk insert from CSV-like staging

Hard
2 views 23 Jan 2026
You loaded ProductsStage. Insert only valid rows (price>0 and name not null) into Products....