Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4608 total questions 4508 technical 100 career & HR 4272 from PDF library

Showing 1–14 of 14

Career & HR topics

By tech stack

Senior PDF
What are common database design patterns?

Short answer: Database design patterns are general solutions to recurring problems that arise in database schema design. Some common patterns include: Real-world example (ShopNest) ShopNest’s SQL Server database stores c…

Senior PDF
What is CAP theorem in distributed databases?

Short answer: The CAP theorem (Consistency, Availability, Partition Tolerance) states that in a distributed database system, it is impossible to simultaneously guarantee all three of the following: Real-world example (Sh…

Senior PDF
What is an eventual consistency model and how does it apply to distributed systems?

Short answer: Eventual consistency is a consistency model used in distributed systems where updates to data will propagate and eventually become consistent across all nodes, but not necessarily immediately. Explain a bit…

Senior Detailed
Write a recursive CTE for an employee–manager hierarchy.

Short answer: Anchor member selects the root manager; recursive member joins employees whose ManagerId equals the CTE EmpId. UNION ALL combines them. Watch MAXRECURSION. Sample solution T-SQL WITH Hierarchy AS ( SELECT E…

Senior Detailed
What is CROSS APPLY vs OUTER APPLY?

Short answer: APPLY invokes a table-valued expression per outer row. CROSS APPLY is like INNER JOIN (outer row must produce rows). OUTER APPLY is like LEFT JOIN (keeps outer rows with NULLs). Useful for TOP N per group a…

APPLY Read answer
Senior Detailed
Write a MERGE statement example for upsert.

Short answer: MERGE matches source to target ON a key, then WHEN MATCHED UPDATE, WHEN NOT MATCHED INSERT. Discuss concurrency and that some teams prefer separate UPDATE/INSERT. Sample solution T-SQL MERGE INTO Employees…

Senior Detailed
How do you find consecutive login days in SQL Server?

Short answer: Gaps-and-islands: ROW_NUMBER() ordered by date, subtract from date to form an island key, then GROUP BY user + island key and count days. Sample solution T-SQL WITH d AS ( SELECT UserId, LoginDate, DATEADD(…

Gaps & Islands Read answer
Senior Detailed
How do you identify blocking or long-running queries (interview theory + DMV)?

Short answer: Talk about DMVs: sys.dm_exec_requests, sys.dm_exec_sessions, sys.dm_os_waiting_tasks, and reading plans. For query writing interviews, also discuss indexes, sargability, and avoiding SELECT *. Sample soluti…

Performance Read answer
Senior
How do you find customers who ordered every month in a year?

Short answer: Filter orders to the year, group by customer, and HAVING COUNT(DISTINCT month) = 12. Sample solution T-SQL SELECT CustomerId FROM Orders WHERE OrderDate >= '2025-01-01' AND OrderDate < '2026-01-01' GR…

GROUP BY & HAVING Read answer
Senior
Write a query to get the median salary in SQL Server.

Short answer: Use PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Salary) OVER (), or pick middle ROW_NUMBER values for odd/even counts. Sample solution T-SQL SELECT DISTINCT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Salar…

Window Functions Read answer
Senior
Write a query using GROUPING SETS / ROLLUP.

Short answer: ROLLUP creates subtotals and a grand total. GROUPING SETS lists exact aggregation levels. GROUPING(col) detects total rows (NULLs that mean “all”). Sample solution T-SQL SELECT DepartmentId, JobTitle, SUM(S…

Aggregation Read answer
Senior
What is a covering index and how does it show up in a query plan?

Short answer: A covering index includes all columns a query needs (key + INCLUDE), enabling an Index Seek/Scan without Key Lookup. In plans, look for absence of Key Lookup and lower estimated cost. Offer: CREATE INDEX ..…

Indexes Read answer
Senior
Write a query to calculate moving average of last 7 days.

Short answer: Use AVG(Amount) OVER (ORDER BY OrderDate ROWS BETWEEN 6 PRECEDING AND CURRENT ROW). Sample solution T-SQL SELECT OrderDate, Amount, AVG(Amount * 1.0) OVER ( ORDER BY OrderDate ROWS BETWEEN 6 PRECEDING AND C…

Window Functions Read answer
Senior
How do you find overlapping date ranges?

Short answer: Two ranges [a,b] and [c,d] overlap when a Sample solution T-SQL SELECT a.Id AS Id1, b.Id AS Id2 FROM Bookings a INNER JOIN Bookings b ON a.Id < b.Id AND a.StartDate <= b.EndDate AND b.StartDate <=…

Intervals Read answer

SQL & Databases SQL Server Tutorial · SQL

Short answer: Database design patterns are general solutions to recurring problems that arise in database schema design. Some common patterns include:

Real-world example (ShopNest)

ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

SQL & Databases SQL Server Tutorial · SQL

Short answer: The CAP theorem (Consistency, Availability, Partition Tolerance) states that in a distributed database system, it is impossible to simultaneously guarantee all three of the following:

Real-world example (ShopNest)

ShopNest’s SQL Server database stores customers, products, and orders. Good indexes and clear foreign keys keep checkout queries fast and safe.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

SQL & Databases SQL Server Tutorial · SQL

Short answer: Eventual consistency is a consistency model used in distributed systems where updates to data will propagate and eventually become consistent across all nodes, but not necessarily immediately.

Explain a bit more

How it works: In an eventually consistent system, updates are made to a node and eventually, that update will be propagated to all other nodes. It allows for temporary inconsistencies, but ensures that the system will converge to a consistent state over time. Use cases: Suitable for systems that can tolerate a delay in consistency, like NoSQL databases (Cassandra, DynamoDB) and systems dealing with high availability and massive scale.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

SQL & Databases SQL Server Tutorial · CTE

Short answer: Anchor member selects the root manager; recursive member joins employees whose ManagerId equals the CTE EmpId. UNION ALL combines them. Watch MAXRECURSION.

Sample solution

T-SQL
WITH Hierarchy AS (
    SELECT EmpId, ManagerId, Name, 0 AS Lvl
    FROM Employees
    WHERE ManagerId IS NULL   -- root
    UNION ALL
    SELECT e.EmpId, e.ManagerId, e.Name, h.Lvl + 1
    FROM Employees e
    INNER JOIN Hierarchy h ON e.ManagerId = h.EmpId
)
SELECT * FROM Hierarchy
ORDER BY Lvl, Name
OPTION (MAXRECURSION 100);

Edge cases to mention

  • Cycles in hierarchy
  • Multiple roots
  • Deep trees hitting recursion limit
Say “anchor + recursive member + termination” — that structure is the interview checklist.
Permalink & share

SQL & Databases SQL Server Tutorial · APPLY

Short answer: APPLY invokes a table-valued expression per outer row. CROSS APPLY is like INNER JOIN (outer row must produce rows). OUTER APPLY is like LEFT JOIN (keeps outer rows with NULLs). Useful for TOP N per group and TVFs.

Sample solution

T-SQL
-- Top 2 orders per customer
SELECT c.CustomerId, c.Name, o.OrderId, o.Amount
FROM Customers c
CROSS APPLY (
    SELECT TOP (2) OrderId, Amount
    FROM Orders o
    WHERE o.CustomerId = c.CustomerId
    ORDER BY Amount DESC
) o;
TOP N per group via CROSS APPLY is a classic SQL Server interview flex.
Permalink & share

SQL & Databases SQL Server Tutorial · DML

Short answer: MERGE matches source to target ON a key, then WHEN MATCHED UPDATE, WHEN NOT MATCHED INSERT. Discuss concurrency and that some teams prefer separate UPDATE/INSERT.

Sample solution

T-SQL
MERGE INTO Employees AS t
USING (SELECT @EmpId AS EmpId, @Name AS Name, @Salary AS Salary) AS s
ON t.EmpId = s.EmpId
WHEN MATCHED THEN
    UPDATE SET Name = s.Name, Salary = s.Salary
WHEN NOT MATCHED THEN
    INSERT (EmpId, Name, Salary) VALUES (s.EmpId, s.Name, s.Salary);
Know that MERGE has historically had race/edge-case caveats — saying so shows maturity.
Permalink & share

SQL & Databases SQL Server Tutorial · Gaps & Islands

Short answer: Gaps-and-islands: ROW_NUMBER() ordered by date, subtract from date to form an island key, then GROUP BY user + island key and count days.

Sample solution

T-SQL
WITH d AS (
    SELECT UserId, LoginDate,
           DATEADD(DAY, -ROW_NUMBER() OVER (PARTITION BY UserId ORDER BY LoginDate), LoginDate) AS grp
    FROM UserLogins
)
SELECT UserId, MIN(LoginDate) AS StartDate, MAX(LoginDate) AS EndDate, COUNT(*) AS Days
FROM d
GROUP BY UserId, grp
HAVING COUNT(*) >= 3;
Naming “gaps and islands” immediately signals senior SQL fluency.
Permalink & share

SQL & Databases SQL Server Tutorial · Performance

Short answer: Talk about DMVs: sys.dm_exec_requests, sys.dm_exec_sessions, sys.dm_os_waiting_tasks, and reading plans. For query writing interviews, also discuss indexes, sargability, and avoiding SELECT *.

Sample solution

T-SQL
SELECT r.session_id, r.status, r.command, r.wait_type, r.blocking_session_id,
       t.text
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
WHERE r.session_id <> @@SPID;
Even app developers score points naming DMVs and “parameter sniffing” briefly.
Permalink & share

SQL & Databases SQL Server Tutorial · GROUP BY & HAVING

Short answer: Filter orders to the year, group by customer, and HAVING COUNT(DISTINCT month) = 12.

Sample solution

T-SQL
SELECT CustomerId
FROM Orders
WHERE OrderDate >= '2025-01-01' AND OrderDate < '2026-01-01'
GROUP BY CustomerId
HAVING COUNT(DISTINCT DATEPART(MONTH, OrderDate)) = 12;
COUNT(DISTINCT month) is the key — COUNT(*) alone is wrong if multiple orders/month.
Permalink & share

SQL & Databases SQL Server Tutorial · Window Functions

Short answer: Use PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Salary) OVER (), or pick middle ROW_NUMBER values for odd/even counts.

Sample solution

T-SQL
SELECT DISTINCT
       PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Salary) OVER () AS MedianSalary
FROM Employees;
PERCENTILE_CONT is continuous; PERCENTILE_DISC picks an actual data value.
Permalink & share

SQL & Databases SQL Server Tutorial · Aggregation

Short answer: ROLLUP creates subtotals and a grand total. GROUPING SETS lists exact aggregation levels. GROUPING(col) detects total rows (NULLs that mean “all”).

Sample solution

T-SQL
SELECT DepartmentId, JobTitle, SUM(Salary) AS TotalSalary
FROM Employees
GROUP BY ROLLUP (DepartmentId, JobTitle);
Use GROUPING() to distinguish real NULL dimension values from rollup NULLs.
Permalink & share

SQL & Databases SQL Server Tutorial · Indexes

Short answer: A covering index includes all columns a query needs (key + INCLUDE), enabling an Index Seek/Scan without Key Lookup. In plans, look for absence of Key Lookup and lower estimated cost.

Offer: CREATE INDEX ... INCLUDE (ColA, ColB) as the practical answer.
Permalink & share

SQL & Databases SQL Server Tutorial · Window Functions

Short answer: Use AVG(Amount) OVER (ORDER BY OrderDate ROWS BETWEEN 6 PRECEDING AND CURRENT ROW).

Sample solution

T-SQL
SELECT OrderDate, Amount,
       AVG(Amount * 1.0) OVER (
           ORDER BY OrderDate
           ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
       ) AS MovingAvg7
FROM DailySales;
ROWS vs RANGE matters when OrderDate has duplicates.
Permalink & share

SQL & Databases SQL Server Tutorial · Intervals

Short answer: Two ranges [a,b] and [c,d] overlap when a <= d AND c <= b (for closed intervals). Self-join bookings/events with that predicate and exclude the same Id.

Sample solution

T-SQL
SELECT a.Id AS Id1, b.Id AS Id2
FROM Bookings a
INNER JOIN Bookings b ON a.Id < b.Id
    AND a.StartDate <= b.EndDate
    AND b.StartDate <= a.EndDate;
Clarify inclusive/exclusive end times — hotel checkout logic often uses half-open intervals.
Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details