Meta: Facebook Groups Where Every Admin Approved a Post

Medium
758.

Meta: Facebook Groups Where Every Admin Approved a Post

The Facebook Groups team checks whether admin teams share the moderation load. A group passes for the week of 2025-03-03 to 2025-03-09 (inclusive) when every one of its current admins approved at least one post in that group during the week.

Return the passing groups with the columns group_id and group_name, in any order. Approvals by people who are not current admins of that group do not count, approvals in another group do not count, and a group with no admins does not pass.

A practice scenario set at Meta: the tables and data are invented, and this is not a question from, or endorsed by, Meta.

Tables

Table: FbGroup

ColumnType
group_idint
group_namevarchar

Primary key: group_id.

One row per Facebook group.

Table: GroupAdmin

ColumnType
group_idint
user_idint

Primary key (together): group_id, user_id.

The current admins of each group.

Table: PostApproval

ColumnType
approval_idint
group_idint
admin_idint
approved_atdate

Primary key: approval_id.

One row per pending post approved; admin_id is the user who approved it (possibly a former admin).

Example

The rows may come back in any order; the columns must be the ones shown, in that order.

FbGroup

group_idgroup_name
1Bengaluru Foodies
2Pune Cyclists
3Kochi Book Club
4Delhi Startup Founders

GroupAdmin

group_iduser_id
110
111
212
213
314

PostApproval

approval_idgroup_idadmin_idapproved_at
11102025-03-03
21112025-03-09
32122025-03-05
42132025-03-10
53142025-03-04
63152025-03-04
71102025-03-06
82132025-03-02

Output

group_idgroup_name
1Bengaluru Foodies
3Kochi Book Club
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

Meta: Facebook Groups Where Every Admin Approved a Post

The Facebook Groups team checks whether admin teams share the moderation load.

  • Difficulty: Medium
  • Topics: Subqueries, Joins, Dates
  • Dialect: MySQL
  • Problem: #758

Problem statement

The Facebook Groups team checks whether admin teams share the moderation load. A group passes for the week of 2025-03-03 to 2025-03-09 (inclusive) when every one of its current admins approved at least one post in that group during the week.

Return the passing groups with the columns group_id and group_name, in any order. Approvals by people who are not current admins of that group do not count, approvals in another group do not count, and a group with no admins does not pass.

A practice scenario set at Meta: the tables and data are invented, and this is not a question from, or endorsed by, Meta.

Tables

Table: FbGroup

ColumnType
group_idint
group_namevarchar

Primary key: group_id.

One row per Facebook group.

Table: GroupAdmin

ColumnType
group_idint
user_idint

Primary key: group_id, user_id.

The current admins of each group.

Table: PostApproval

ColumnType
approval_idint
group_idint
admin_idint
approved_atdate

Primary key: approval_id.

One row per pending post approved; admin_id is the user who approved it (possibly a former admin).

Examples

Example 1

FbGroup

group_idgroup_name
1Bengaluru Foodies
2Pune Cyclists
3Kochi Book Club
4Delhi Startup Founders

GroupAdmin

group_iduser_id
110
111
212
213
314

PostApproval

approval_idgroup_idadmin_idapproved_at
11102025-03-03
21112025-03-09
32122025-03-05
42132025-03-10
53142025-03-04
63152025-03-04
71102025-03-06
82132025-03-02

Output

group_idgroup_name
1Bengaluru Foodies
3Kochi Book Club

How to solve Meta: Facebook Groups Where Every Admin Approved a Post

This is relational division: keep a group only if all of its admins have a matching approval. SQL has no "for all", so the solution uses the double negative — there is no admin of the group for whom there is no approval. The innermost NOT EXISTS asks whether one admin approved something in that group between 3 and 9 March; the outer NOT EXISTS requires that no admin fails that test.

A universal statement over an empty set is true, so a group without admins would pass the double negative. The statement says it must not, hence the extra EXISTS on GroupAdmin. Approvals by former admins never match a GroupAdmin row, and an approval in another group fails the p.group_id = a.group_id test, so neither helps.

The counting alternative joins every admin to their distinct approvals in the week (a LEFT JOIN, so admins without one keep a NULL row) and keeps groups where the number of admins equals the number of matched admins. The inner join to GroupAdmin drops admin-less groups by itself. Both are linear with indexes on the join keys.

Reference solution (MySQL)

SELECT g.group_id, g.group_name
FROM FbGroup g
WHERE EXISTS (SELECT 1 FROM GroupAdmin a WHERE a.group_id = g.group_id)
  AND NOT EXISTS (
    SELECT 1 FROM GroupAdmin a
    WHERE a.group_id = g.group_id
      AND NOT EXISTS (
        SELECT 1 FROM PostApproval p
        WHERE p.group_id = a.group_id AND p.admin_id = a.user_id
          AND p.approved_at BETWEEN '2025-03-03' AND '2025-03-09'))

Another way

SELECT g.group_id, g.group_name
FROM FbGroup g
JOIN GroupAdmin a ON a.group_id = g.group_id
LEFT JOIN (SELECT DISTINCT group_id, admin_id FROM PostApproval
           WHERE approved_at BETWEEN '2025-03-03' AND '2025-03-09') p
       ON p.group_id = a.group_id AND p.admin_id = a.user_id
GROUP BY g.group_id, g.group_name
HAVING COUNT(*) = COUNT(p.admin_id)

← Meta: Last-Click Attributed Revenue by Campaign · Meta: WhatsApp Business Message Delivery Funnel →