← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

SQL screen for a Data Scientist role at Meta. Two parts, both around reply engagement on a posts table. Pretty standard stuff but the zero-reply edge case tripped me up more than I'd like to admit.

Questions Asked (2)

Q1

Given a posts table and a replies table, return every post along with its reply count. Posts with zero replies should still appear in the result, showing a count of 0. Order by reply count descending, then post_id ascending.

Data ModelingProduct Analytics & Metrics
Author's notes

My first instinct was a regular join and I almost wrote it that way before catching myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the table schemas and the definition of a reply (e.g., whether replies can be nested or deleted). Then use a LEFT JOIN from posts to replies, group by post, and count replies, ensuring zero-reply posts are included. Finally, apply the specified ordering with a tie-breaker on post_id.

Pro tip: Mention that using COUNT(replies.id) instead of COUNT(*) avoids counting NULLs from the LEFT JOIN, and explicitly state the ordering logic to show attention to detail.

1. Clarify requirements and schema

Confirm the structure of the posts and replies tables, including primary/foreign keys, and whether replies can be deleted or nested. Ask if the reply count should include all replies or only top-level ones.

2. Choose the join strategy

Use a LEFT JOIN from posts to replies to ensure all posts are included, even those without replies. Alternatively, consider a correlated subquery or a pre-aggregated CTE for performance.

3. Aggregate and count

Group by post_id (and any other post columns needed) and count the replies using COUNT(replies.id) to handle NULLs correctly. Alias the count as reply_count.

4. Apply ordering

Order the results by reply_count descending, then by post_id ascending to meet the tie-breaking requirement.

5. Validate edge cases

Mentally test with posts having zero replies, multiple replies, and ties in reply counts. Ensure the query returns the expected results and discuss potential performance considerations.

Key Points to Mention

  • LEFT JOIN ensures posts with zero replies are included.
  • COUNT(replies.id) correctly returns 0 for posts with no replies, unlike COUNT(*).
  • Grouping by post_id is necessary for aggregation.
  • Ordering by reply_count DESC, post_id ASC satisfies the requirement.
  • Consider performance implications of joining large tables and possible indexing.
  • Clarify if replies table has a foreign key to posts and if there are any filters (e.g., deleted replies).

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

Q2

Using the same schema, return only the post IDs of posts that have received no replies at all, ordered by post_id ascending.

Data ModelingProduct Analytics & Metrics
Author's notes

Two ways to do this and I went with NOT EXISTS instead of a LEFT JOIN + WHERE NULL check.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Identify the posts table and the replies table (or a self-referencing parent_post_id column) in the given schema, then use a LEFT JOIN or NOT EXISTS subquery to find posts with no matching replies. Filter out posts that have at least one reply and order the remaining post IDs ascending.

Pro tip: Clarify whether 'no replies' includes deleted or hidden replies; if so, add a filter to exclude them. Also, consider performance: NOT EXISTS is often more efficient than LEFT JOIN with NULL check on large datasets.

1. Understand the schema

Identify the posts table and the replies table (or self-referencing column) and the key that links replies to posts.

2. Choose an anti-join method

Decide between LEFT JOIN with IS NULL, NOT EXISTS, or NOT IN based on performance and null-handling requirements.

3. Write the query

Construct the SQL query to select post IDs from posts where no matching reply exists, ensuring correct join condition.

4. Order and filter

Add ORDER BY post_id ASC and consider any additional filters (e.g., exclude deleted posts).

5. Validate and optimize

Check for edge cases (e.g., posts with replies that are deleted) and ensure the query uses indexes efficiently.

Key Points to Mention

  • Use of LEFT JOIN with WHERE reply_id IS NULL to find non-matching rows
  • Alternative: NOT EXISTS subquery for better performance on large datasets
  • Handling of NULLs in the join condition (e.g., if reply.post_id can be NULL)
  • Consideration of deleted or hidden replies and whether they count as replies
  • Indexing on the foreign key column (e.g., reply.post_id) to speed up the anti-join
  • Ordering by post_id ascending as specified

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