SQL Interview Practice in Sri Lanka: Questions and Checks

SQL interview practice becomes more useful when you can explain what each row represents and verify the result by hand. For Sri Lankan data and software candidates, a small order dataset is enough to practise joins, grouping and missing records.
Use the SQL dialect expected by the role. The examples below use ordinary syntax that is suitable for a PostgreSQL practice database.
Build a tiny dataset
Create two customers and three orders, including one customer with no orders:
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER REFERENCES customers(id),
amount NUMERIC(10, 2) NOT NULL
);
INSERT INTO customers VALUES (1, 'Sample A'), (2, 'Sample B');
INSERT INTO orders VALUES (101, 1, 1200), (102, 1, 800), (103, 1, 500);
These are fictional records. The total for Sample A is 2500, and Sample B has no orders.
Before writing a query, state whether the result should include customers with no orders. That requirement changes the join choice.
Practise a grouped result
SELECT c.id, c.name,
COUNT(o.id) AS order_count,
COALESCE(SUM(o.amount), 0) AS total_amount
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.id
GROUP BY c.id, c.name
ORDER BY c.id;
The expected rows are Sample A with three orders and 2500, and Sample B with zero orders and zero.
The PostgreSQL joins tutorial explains how joins combine rows. Its aggregate-functions tutorial covers grouping and aggregate calculations.
Explain the important choices
| Choice | Reason in this example |
|---|---|
| LEFT JOIN | Retains the customer with no orders |
| COUNT(o.id) | Counts matched orders rather than the unmatched row |
| SUM(o.amount) | Adds the customer's order amounts |
| COALESCE | Displays zero when the sum is null |
| GROUP BY | Produces one result per customer |
Be ready to explain why COUNT(*) would produce a different count for the customer without orders. Memorising the query without understanding that distinction misses the point.
Add one change at a time
Insert an order for Sample B and predict the new result before running the query. Then add a date column and practise restricting the period.
Pay attention to where a filter is placed. A condition on the right-hand table in WHERE can remove unmatched rows after a LEFT JOIN. Decide whether that matches the requirement.
Try a duplicate join key in a separate practice table and observe how it multiplies results. This helps explain why a dashboard total can be wrong even when the SQL runs successfully.
Prepare for the conversation
Explain your assumptions before coding. Ask whether cancelled orders, returns or missing amounts should count.
After writing the query, describe how you would validate it: check a small sample, compare totals and inspect unexpected row counts.
If you make a mistake, correct it openly and explain the cause. Interviewers can learn from your debugging process as well as the final query.
Should you memorise many SQL questions?
Practise the underlying concepts and how requirements change the query. A small dataset with several variations teaches more than copying unrelated solutions.
Is a query correct because it returns rows?
No. The result must match the business question, row meaning and treatment of missing data.
What should you do with NULL values?
Decide what they mean in the dataset. Do not automatically replace every missing value with zero.
How can you show this work in a portfolio?
Include the schema, sample data, questions, queries and expected results so another person can reproduce your reasoning.
Related guides
- Data Analyst Portfolio in Sri Lanka: Sales Project Guide
- Power BI Portfolio in Sri Lanka: Build a Useful Dashboard
- Excel Skills for Jobs in Sri Lanka: A Practice Project
Browse the Sri Lanka work and technology guides for more practical application, AI and workplace projects.
Related articles
About the author
App Dev Sri Lanka prepared this guide with AI assistance, original examples and the linked primary sources. The collection was informed by Google Trends research for Sri Lanka on 2 September 2026. Illustrations depict fictional people. Examples are educational; this article is not a live vacancy notice or an employer endorsement.
Learn more about App Dev Sri Lanka



