Data Engineering · SQL
How SQL Helps Land a Data Engineer Job in India
Quick summary — how SQL helps land a data engineer job
Here is how SQL helps land a data engineer job: interviews and real pipelines both depend on SQL patterns beyond basic queries — deduplication with window functions, upserts with MERGE, history tables with slowly changing dimensions, incremental loads and data quality checks. Being fluent in these lets you clear technical rounds and contribute from your first week.
In this guide you will learn:
- Core DE SQL patterns — dedup, upserts and incremental loads.
- Modelling with SQL — facts, dimensions and SCD Type 2.
- Data quality SQL — queries that catch bad data.
- Practice templates — a problem set and interview tracker.
- Interview prep — the SQL questions data engineers face.
SECTION 01Loading data: deduplication, upserts and incremental loads
Raw data arrives with duplicates, late updates and changes. Data engineers use SQL to load it so that reruns are safe and tables stay correct. These patterns appear constantly in interviews.
| Pattern | Problem it solves | Key SQL | Interview phrasing |
|---|---|---|---|
| Deduplication | Same record arrives more than once | ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) | 'Keep the latest record per customer' |
| Upsert | Insert new rows, update changed ones | MERGE or INSERT ... ON CONFLICT | 'Load daily changes into a target table' |
| Incremental load | Avoid reprocessing all history | WHERE updated_at > last watermark | 'How would you load only new data?' |
| Idempotency | Reruns must not duplicate data | Delete-insert by partition or MERGE | 'What if the job runs twice?' |
-- Keep the latest version of each order from a raw table
WITH ranked AS (
SELECT *,
ROW_NUMBER() OVER (
PARTITION BY order_id
ORDER BY updated_at DESC
) AS rn
FROM raw_orders
)
SELECT order_id, customer_id, amount, status, updated_at
FROM ranked
WHERE rn = 1;
-- Target table must have a unique key on order_id
INSERT INTO orders (order_id, customer_id, amount, status, updated_at)
SELECT order_id, customer_id, amount, status, updated_at
FROM staging_orders
ON CONFLICT (order_id) DO UPDATE
SET customer_id = EXCLUDED.customer_id,
amount = EXCLUDED.amount,
status = EXCLUDED.status,
updated_at = EXCLUDED.updated_at
WHERE orders.updated_at < EXCLUDED.updated_at;
SECTION 02Modelling data: facts, dimensions and history
Data engineers shape data so analysts can use it easily. That means fact and dimension tables, and sometimes keeping history when attributes change — known as slowly changing dimensions.
| Concept | Meaning | SQL technique | Example |
|---|---|---|---|
| Fact table | Events with measures | Aggregations, joins to dimensions | fact_orders(amount, order_date_key, customer_key) |
| Dimension table | Descriptive attributes | Surrogate keys, lookups | dim_customer(city, segment) |
| SCD Type 1 | Overwrite old values | UPDATE | Fix a typo in a name |
| SCD Type 2 | Keep history of changes | Close old row, insert new row with dates | Customer moves from Noida to Pune |
-- 1. Close current rows whose tracked attribute changed
UPDATE dim_customer d
SET valid_to = CURRENT_DATE, is_current = FALSE
FROM staging_customers s
WHERE d.customer_id = s.customer_id
AND d.is_current
AND d.city <> s.city;
-- 2. Insert new current rows for changed or new customers
INSERT INTO dim_customer (customer_id, city, valid_from, valid_to, is_current)
SELECT s.customer_id, s.city, CURRENT_DATE, NULL, TRUE
FROM staging_customers s
LEFT JOIN dim_customer d
ON d.customer_id = s.customer_id AND d.is_current
WHERE d.customer_id IS NULL;
-- Which city was the customer in when each order happened?
SELECT o.order_id, o.order_date, d.city
FROM fact_orders o
JOIN dim_customer d
ON d.customer_id = o.customer_id
AND o.order_date >= d.valid_from
AND (d.valid_to IS NULL OR o.order_date < d.valid_to);
SECTION 03Data quality checks in SQL
A pipeline that runs but loads bad data is worse than one that fails. Data engineers write simple SQL checks that run after each load and stop or alert when something looks wrong.
| Check | What it catches | SQL idea | Action on failure |
|---|---|---|---|
| Uniqueness | Duplicate keys | GROUP BY key HAVING COUNT(*) > 1 | Fail the load |
| Completeness | Missing required values | COUNT(*) WHERE col IS NULL | Fail or quarantine rows |
| Validity | Out-of-range values | WHERE amount < 0 OR status NOT IN (...) | Alert and review |
| Freshness and volume | Late or missing data | MAX(updated_at), row count vs average | Alert the on-call engineer |
-- Each query should return 0 rows / 0 count when data is healthy
SELECT order_id, COUNT(*) FROM orders GROUP BY order_id HAVING COUNT(*) > 1;
SELECT COUNT(*) AS null_customers FROM orders WHERE customer_id IS NULL;
SELECT COUNT(*) AS bad_amounts FROM orders WHERE amount < 0;
SELECT COUNT(*) AS bad_status
FROM orders WHERE status NOT IN ('pending','paid','shipped','cancelled');
-- Compare today's load with the 7-day average
WITH daily AS (
SELECT DATE(updated_at) AS d, COUNT(*) AS n
FROM orders
WHERE updated_at >= CURRENT_DATE - INTERVAL '8 days'
GROUP BY DATE(updated_at)
)
SELECT (SELECT n FROM daily WHERE d = CURRENT_DATE) AS today,
(SELECT AVG(n) FROM daily WHERE d < CURRENT_DATE) AS avg_7d;
-- alert if today is far below avg_7d
SECTION 04SQL practice templates for data engineers
Use these templates to structure your SQL preparation and track interview performance.
Data Engineer SQL Problem Set
1. Latest record per key (ROW_NUMBER)
2. Running total per customer (SUM OVER)
3. Gaps in daily data (date series + LEFT JOIN)
4. Upsert staging into target
5. SCD Type 2 load
6. Sessionise events (LAG + 30-minute rule)
7. Top N per group
8. Pivot rows to columns with CASE
9. Find duplicate keys and their counts
10. Month-over-month growth (LAG)
SQL Practice Log
Date Problem Solved alone? Time Edge cases noted
______ ______________ Y / N ____ ______________
______ ______________ Y / N ____ ______________
Redo any 'N' after three days without looking.
Interview Tracker (SQL rounds)
Company Question Pattern Outcome
_______ ______________________ dedup/window/... ______
_______ ______________________ ______________ ______
Patterns I struggled with: ______________
SECTION 05Tips for data engineering SQL preparation
Use these habits to make SQL your strongest interview skill:
- Think in sets — write queries that work on whole tables, not row by row.
- Master window functions — ROW_NUMBER, LAG and SUM OVER solve many DE problems.
- Explain edge cases — late data, duplicates and NULLs are what interviewers probe.
- Read query plans — know how indexes and partitions affect performance.
- Practise on realistic data — messy staging tables teach more than clean examples.
SECTION 06Interview Q&A — SQL for data engineers
Q1How do you remove duplicates while keeping the latest record?
Use ROW_NUMBER() partitioned by the key and ordered by an update timestamp descending, then keep rows where the row number is 1.
Q2What is an upsert?
An operation that inserts a row if it does not exist and updates it if it does, implemented with MERGE or INSERT ... ON CONFLICT.
Q3What is a slowly changing dimension Type 2?
A dimension design that keeps history by closing the old row with an end date and inserting a new current row when an attribute changes.
Q4How do you make a pipeline idempotent in SQL?
Use upserts or delete-and-reload by partition so rerunning the same load produces the same final data.
Q5How do you detect missing days in a daily table?
Generate a series of dates, LEFT JOIN the table to it and find dates with no matching rows.
SECTION 07Test yourself — SQL for data engineers quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Is SQL enough to become a data engineer?
SQL is essential but not enough alone. You also need Python, data modelling, pipeline tools and cloud basics.
What SQL topics are asked in data engineer interviews in India?
Window functions, joins, deduplication, upserts, slowly changing dimensions, incremental loads, query performance and data quality checks.
Which SQL database should I practise on?
PostgreSQL is a good free choice. Most patterns transfer to cloud warehouses with small syntax changes.
How long does it take to get strong at SQL for data engineering?
With daily practice on realistic problems, many learners become interview-ready in a few months.
Should data engineers learn MERGE?
Yes. MERGE or its equivalents are central to loading changes into target tables in most warehouses.
SECTION 09Related reads
Classroom & online · Noida
Build SQL skills employers test
Our Data Analytics Training Course builds deep SQL — joins, window functions, CTEs and data modelling — alongside Excel, Python and Power BI.
₹15,500 · full programme- Advanced SQL practice
- Data modelling projects
- Mock interviews
- Weekday & weekend batches