AI Interview Assistant for SQL Interviews

A SQL interview tests how you turn a question into the right rows, then explain why the query works. Hiintly helps you interpret a schema, reason through joins and window functions, and answer follow-ups during the conversation. Share the written prompt with screenshot analysis and use the interview audio to keep new requirements in context.

What happens in a SQL interview?

You may write a query in a shared editor, discuss an existing query or debug an incorrect result. The format and order vary by employer. Across these tasks, expect questions about the meaning of the data, your choice of SQL operations and how the answer changes under a new rule. Start with the part you need to explain most clearly.

Read the schema before writing SQL

“Which customers have never submitted a support ticket?”

A prompt may arrive in a shared editor, a document or a spoken question. Identify the primary keys, the relationship between tables and what one output row should represent. Ask whether test accounts or deleted tickets count.

Capture the prompt and schema with Hiintly’s screenshot analysis. Ask for clarifying questions before a query. Explain why NOT EXISTS can express “no matching ticket” without duplicating customers who have several tickets.

Explain joins, filters and aggregation

“Show every team and its number of open tickets, including teams with none.”

This tests whether you preserve unmatched teams and count the right rows. With a left join, place the open-status condition in the join and count a non-null ticket key. COUNT(*) would count the unmatched team’s placeholder row.

Give Hiintly your query and the interviewer’s question. Request a trace for one team with two open tickets and one with none. Use the suggestion to explain why the counts should be two and zero, and why a WHERE filter on the ticket status would remove the empty team.

Handle ranking and a changed requirement

“Find the second-highest salary in each department. What if salaries tie?”

The interviewer can change a rule after your first solution: include ties, return exactly one employee, or keep departments without a second salary. Clarify the required output before choosing a window function.

Use the interview audio for the new condition, or type it and press Send. Ask Hiintly which part of the query needs to change and which sample rows would reveal a mistake. The worked example below follows this conversation through to a result.

Give Hiintly the SQL context

Add the job description and your resume when setting up the interview session. Include the SQL dialect, the expected level and the kind of work the role involves in Extra Instructions. For a mixed technical conversation, choose the existing Software Engineer interview type; use Data Analytics when the round centers on analysis.

During the interview, capture the table definitions and written task together when possible. If the screenshot omits a key detail, type it and press Send. Spoken follow-ups provide conversation context; a screenshot of your current query or an error adds the details needed to discuss a correction.

Make the instructions specific

“This is a PostgreSQL interview. Help me state the output grain and assumptions before suggesting a query. Explain how joins affect row counts. For ranking questions, ask whether ties count and show a small example.”

For a role with broader responsibilities, connect the query to the decision it supports. The data analyst interview page covers metric interpretation; the data engineer interview page covers data quality and pipeline follow-ups.

Find the second-highest salary, including ties

The interviewer shares an employees table with one row per employee: employee_id, department_id, salary and is_active. The task is to return every active employee earning the second-highest distinct salary in their department. Unknown salaries do not qualify. A separate departments table has one row per department.

Turn the prompt into a query plan

Capture the schema and task in Hiintly, then send: “We need all employees tied at the second distinct active salary. Help me explain the window function and where to filter inactive employees.” A useful suggestion starts by filtering the eligible employees, ranking salaries within each department and selecting rank two in an outer query.

Say why you chose DENSE_RANK: equal salaries receive the same rank, and the next distinct salary gets the next number. Filtering inactive employees before ranking prevents an inactive high earner from shifting the result.

Trace the output

Engineering has active salaries Ada 120, Bo 110, Cy 110 and Di 90. Their ranks are 1, 2, 2 and 3, so Bo and Cy appear, each with salary 110. Operations has Eva 100 and Fay 100. Both rank first, so Operations has no qualifying row.

Rank eligible rows within each department

WITH ranked AS (
    SELECT employee_id, department_id, salary,
           DENSE_RANK() OVER (
               PARTITION BY department_id
               ORDER BY salary DESC
           ) AS salary_rank
    FROM employees
    WHERE is_active = TRUE
      AND salary IS NOT NULL
)
SELECT department_id, employee_id, salary
FROM ranked
WHERE salary_rank = 2
ORDER BY department_id, employee_id;

The follow-up: keep departments with no second salary

The interviewer adds: “Include every department, even if no employee qualifies.” Let the new condition enter the interview conversation, or send it as a message. Ask Hiintly to revise the final join while keeping the existing ranked CTE. Start from departments and left join only rank-two employees.

Keep salary_rank = 2 in the join condition. Moving it to WHERE would reject the null row for Operations. The revised result contains Bo and Cy for Engineering and one Operations row with null employee and salary values. An empty department also appears once with null values.

Explain the change aloud: “The ranking rule stays the same. I’ve changed which departments survive the final query. The left join preserves every department, and its join condition only attaches employees at the second distinct salary. Null here means no qualifying employee, so I won’t replace it with a salary of zero.”

Replace the final SELECT, keeping the CTE above

SELECT d.department_id, r.employee_id, r.salary
FROM departments AS d
LEFT JOIN ranked AS r
  ON r.department_id = d.department_id
 AND r.salary_rank = 2
ORDER BY d.department_id, r.employee_id;

Practice questions with results you can explain

Change one rule, then predict the rows

Revisit the salary example with two people tied at the highest salary. RANK would skip rank two, while DENSE_RANK still finds the second distinct salary. If the interviewer instead requests exactly the second employee, clarify a tie-breaker and use ROW_NUMBER with salary descending and a stable employee key. That is a different question with a different output.

Use an error as the next interview question

Execute the query in your SQL environment. If the result differs from your prediction, send Hiintly the query, a few input rows and the unexpected output. Ask which operation first changes the row count incorrectly. For more prompts, choose an exercise from the SQL interview questions and answers guide and explain the expected output before checking its solution.

SQL interview FAQ

What are common SQL interview questions?

Common exercises ask you to join related tables, aggregate at a specified grain, find missing matches, rank rows or compare activity over time. Prepare to explain duplicates, nulls and ties as well as syntax. A correct query should match the requested output when a group has no rows or several equally ranked rows.

How should I practice basic SQL interview questions?

Start with SELECT, WHERE, GROUP BY and joins on small tables whose results you can calculate yourself. Write the expected output first, then compare it with the query result. Add one edge case at a time, such as an unmatched parent row or a null value, and explain what changes.

How do I explain SQL interview answers instead of just showing a query?

State the output grain, describe which rows qualify and explain how each join or aggregation changes the rows. Then trace a small example and name one edge case. If you use a window function, explain its partition, ordering and tie behavior so the interviewer can follow the choice.

Should I use RANK, DENSE_RANK or ROW_NUMBER for salary questions?

Use the required output to decide. DENSE_RANK identifies the second distinct salary without gaps after ties. RANK leaves gaps, so two employees tied at rank one can make the next rank three. ROW_NUMBER gives each row a separate number; add a deterministic tie-breaker when exactly one employee must be selected.

Can Hiintly run my SQL query?

Hiintly provides suggestions from interview audio, conversation context, screenshots and messages you send. Use the interview editor or your database environment to execute a query and inspect its result. Send an error or unexpected output back as context when you need help reasoning through a correction.

Explain your next SQL answer with Hiintly

Bring the schema, the question and your reasoning. Use Hiintly to work through the query and respond when the interviewer changes a condition.