← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

SQL screen for a SWE role at Meta. Just the one question, pretty straightforward aggregation stuff, nothing that should trip you up if you've done any SQL before.

Questions Asked (1)

Q1

Given an impressions table with columns ad_id, timestamp, and user_id, write a SQL query that returns the total number of impressions per ad.

Data ModelingProduct Analytics & Metrics
Author's notes

Pretty much just a GROUP BY with a COUNT.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the table schema and the definition of an impression, then write a simple GROUP BY query to count rows per ad_id. Explain your reasoning and consider edge cases like NULL values or duplicate rows.

Pro tip: Mention that you'd confirm whether each row represents a unique impression or if deduplication is needed, and discuss indexing on ad_id for performance at scale.

1. Clarify requirements

Ask if each row is a unique impression and if there are any filters (e.g., time range) or specific ad_id values to include.

2. Identify aggregation

Recognize that the total number of impressions per ad is a simple count of rows grouped by ad_id.

3. Write the query

Use SELECT ad_id, COUNT(*) AS impression_count FROM impressions GROUP BY ad_id; optionally add ORDER BY for readability.

4. Consider edge cases

Discuss handling NULL ad_id values, duplicate rows, and whether to use COUNT(*) or COUNT(DISTINCT user_id) based on the definition of an impression.

5. Optimize and scale

Mention indexing on ad_id and partitioning by timestamp for large datasets to improve query performance.

Key Points to Mention

  • GROUP BY ad_id with COUNT(*) for total impressions
  • Clarify if an impression is a row or a unique user-ad interaction
  • Handle NULL ad_id values appropriately (e.g., exclude or include)
  • Consider using COUNT(DISTINCT user_id) if impressions are defined per user
  • Index on ad_id to speed up grouping and filtering
  • Partitioning by timestamp for efficient time-range queries

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