Find Comments Whose Parent Post Was Soft Deleted
Last updated: November 29, 2026
Quick Overview
Facebook posts are soft deleted by setting deleted_at, but comments are not always cleaned up. Count comments per day that point to a post that is missing or soft deleted at the time the report runs.
Meta
November 29, 20260
0
0 solved
Facebook posts are soft deleted by setting deleted_at, but comments are not always cleaned up. Count comments per day that point to a post that is missing or soft deleted at the time the report runs.
Referential integrity checks are a staple for Meta engineers who own data in large sharded stores where foreign keys are not enforced. The interviewer checks LEFT JOIN anti-join logic and the difference between missing and soft-deleted parents.
What the Interviewer Expects
- Uses LEFT JOIN from comments to posts
- Distinguishes missing parents (NULL join) from soft-deleted parents
- Keeps the deleted_at filter in the right clause
- Groups by comment day
- Explains why the comment count should not be done with an inner join
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you ignore comments created after the post was deleted vs before?
- How would you turn this into a daily data quality alert?
- How would you clean these up safely?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
comments(comment_id, post_id, created_at) and posts(post_id, author_id, deleted_at). A post can be hard deleted (row gone, typical after retention windows) or soft deleted (deleted_at set). I re...
Approach
LEFT JOIN comments to posts on post_id. If the post side is NULL, the parent is missing. If it matched but deleted_at is set, it is soft deleted. Everything else is healthy and filtered out. I keep ...