← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Amazon BI Engineer interview with a SQL data quality question. Pretty straightforward anti-join scenario, nothing too wild, but it's the kind of thing that trips you up if you go blank on syntax under pressure.

Questions Asked (1)

Q1

Given an EMPLOYEE table and a DEPARTMENT table, write a SQL query to return all employees whose department ID does not exist in the DEPARTMENT table.

Data ModelingTechnical Trade-offs
Author's notes

Classic orphaned-record problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and the exact requirement (orphaned employees). Then present a correct SQL query using either NOT EXISTS or LEFT JOIN ... IS NULL, and briefly compare the two approaches in terms of performance and readability. Finally, mention edge cases like NULL department IDs and indexing.

Pro tip: In interviews, explicitly state your assumption about NULL department IDs and how your query handles them; this shows attention to data quality and prevents subtle bugs. Also, mention that NOT EXISTS is often more efficient than NOT IN when NULLs are present.

1. Clarify the schema and requirement

Confirm the columns of EMPLOYEE and DEPARTMENT tables, especially the join key (e.g., dept_id) and whether NULLs are allowed. Restate the goal: find employees whose department ID has no matching record in DEPARTMENT.

2. Choose a query pattern

Select an approach: NOT EXISTS, LEFT JOIN with IS NULL, or NOT IN (with caution). Explain why you prefer one, e.g., NOT EXISTS handles NULLs safely and often performs well.

3. Write the SQL query

Write the query clearly, using aliases and proper formatting. For example: SELECT e.* FROM EMPLOYEE e WHERE NOT EXISTS (SELECT 1 FROM DEPARTMENT d WHERE d.dept_id = e.dept_id);

4. Discuss performance and trade-offs

Mention indexing on the join columns, and compare NOT EXISTS vs LEFT JOIN vs NOT IN in terms of execution plan and NULL handling. Note that NOT IN can return unexpected results if the subquery returns NULL.

5. Address edge cases and validation

Consider employees with NULL department IDs (they won't match any department, so they should be included if the requirement is 'does not exist'). Suggest testing with sample data or explaining how to verify correctness.

Key Points to Mention

  • Use of NOT EXISTS or LEFT JOIN ... IS NULL to find non-matching rows.
  • NULL handling: NOT IN fails if subquery returns NULL; NOT EXISTS is safe.
  • Performance considerations: indexing on join columns, and how the query optimizer may treat different patterns.
  • Readability and maintainability: choose a pattern that is clear to other engineers.
  • Edge case: employees with NULL department ID should be included as they don't exist in DEPARTMENT.
  • Alternative: using EXCEPT or MINUS (if supported) to find orphaned department IDs, but then need to join back to EMPLOYEE.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.