← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

SQL interview for a BI Engineer role at Amazon. One question, pretty focused on joins and aggregation logic across a small e-commerce schema. Nothing wild but you have to get the filtering right or the count is off.

Questions Asked (1)

Q1

Given tables for customers, orders, order items, and items, write a SQL query that returns the count of distinct customers who purchased both a Kindle and an Alexa.

Data ModelingProduct Analytics & Metrics
Author's notes

I went straight for a join across all four tables and then tried to filter in the WHERE clause, which almost immediately broke things because you end up excluding rows you need for the other item.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and the definition of 'purchased both' (e.g., within the same order or across any orders). Then write a query that joins customers to orders to order items to items, filters for Kindle and Alexa, and counts distinct customers who have both products using a self-join or conditional aggregation.

Pro tip: Mention that you would verify the query's correctness with edge cases (e.g., customers who bought multiple Kindles, or only one of the products) and discuss performance considerations like indexing on item names and customer IDs.

1. Clarify requirements and schema

Ask whether 'purchased both' means in the same order or across any orders, and confirm the table relationships (e.g., customers->orders->order_items->items).

2. Identify relevant items

Filter the items table to get the item IDs for 'Kindle' and 'Alexa', or use a subquery/CTE to isolate these products.

3. Join tables to find purchases

Join customers, orders, order_items, and items to link customers to the products they purchased, ensuring you capture all relevant orders.

4. Count distinct customers with both products

Use conditional aggregation (e.g., COUNT(DISTINCT CASE WHEN ...)) or a self-join to find customers who have at least one Kindle and at least one Alexa purchase, then count them.

5. Validate and optimize

Test with edge cases and consider indexing or query performance improvements, such as filtering early or using EXISTS clauses.

Key Points to Mention

  • Use of DISTINCT to avoid double-counting customers with multiple purchases.
  • Handling of NULLs or missing data in joins.
  • Choice between self-join and conditional aggregation for clarity and performance.
  • Importance of filtering on item names early to reduce dataset size.
  • Consideration of whether the purchase must be in the same order or can be across orders.
  • Potential need for indexing on item names and foreign keys for efficiency.

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