InterviewPrepKit

Home / SQL / Advanced Patterns

Emails That Signed Up In Exactly One Year

medium
Solving tips
  • Set operators (UNION, INTERSECT, EXCEPT) match on the full row and, unlike their ALL variants, deduplicate automatically.
  • A symmetric difference is (A EXCEPT B) UNION (B EXCEPT A) — the emails in one set but not the other, from both directions.
  • Parenthesize each EXCEPT branch, and put the final ORDER BY after the last query so it applies to the combined result.

You have two yearly signup lists. Find the emails that appear in one year but not the other (the symmetric difference).

Schema

CREATE TABLE signups_2023 (email TEXT);
CREATE TABLE signups_2024 (email TEXT);

Sample data:

signups_2023

email
[email protected]
[email protected]
[email protected]
[email protected]

signups_2024

email
[email protected]
[email protected]
[email protected]
[email protected]

Task

Return the single column email for every address that appears in exactly one of the two tables (present in 2023 but not 2024, or present in 2024 but not 2023). Order by email ascending.

Expected output

email
[email protected]
[email protected]
[email protected]
[email protected]
Your workspace Not runnable by design — this is your interview scratchpad. Saved on this device.