Second Day Verification - Problem
Second Day Verification is a SQL database problem that challenges you to identify users who verified their email addresses exactly one day after signing up.
You're given two tables:
Goal: Return user IDs of those who verified on the second day, ordered by
Key Insight: You need to join the tables, filter for 'Verified' actions, and check if the action date is exactly 1 day after the signup date using date arithmetic.
You're given two tables:
emails containing user signup information and texts containing verification actions. Your task is to find users who successfully verified their accounts on the second day (exactly 1 day after their signup date).Goal: Return user IDs of those who verified on the second day, ordered by
user_id ascending.Key Insight: You need to join the tables, filter for 'Verified' actions, and check if the action date is exactly 1 day after the signup date using date arithmetic.
Input & Output
example_1.sql โ Basic Case
$
Input:
emails: [(125, 7771, '2022-06-14 09:30:00'), (433, 1052, '2022-07-09 08:15:00'), (234, 7005, '2022-08-20 10:00:00')]\ntexts: [(1, 125, 'Verified', '2022-06-15 08:30:00'), (2, 433, 'Not Verified', '2022-07-10 10:45:00'), (4, 234, 'Verified', '2022-08-21 09:30:00')]
โบ
Output:
[7005, 7771]
๐ก Note:
User 7771 signed up on 2022-06-14 and verified on 2022-06-15 (next day). User 7005 signed up on 2022-08-20 and verified on 2022-08-21 (next day). User 1052 did not verify successfully.
example_2.sql โ Same Day Verification
$
Input:
emails: [(100, 5001, '2022-01-01 10:00:00'), (200, 5002, '2022-01-02 11:00:00')]\ntexts: [(10, 100, 'Verified', '2022-01-01 15:00:00'), (20, 200, 'Verified', '2022-01-04 12:00:00')]
โบ
Output:
[]
๐ก Note:
User 5001 verified on the same day (not second day). User 5002 verified on the third day (not second day). No users verified on exactly the second day.
example_3.sql โ Multiple Actions
$
Input:
emails: [(300, 6001, '2022-03-01 08:00:00')]\ntexts: [(30, 300, 'Not Verified', '2022-03-02 09:00:00'), (31, 300, 'Verified', '2022-03-02 14:00:00')]
โบ
Output:
[6001]
๐ก Note:
User 6001 had multiple verification attempts on the second day. Since they eventually verified on the second day (2022-03-02), they should be included in results.
Constraints
- 1 โค emails.length โค 1000
- 1 โค texts.length โค 1000
- email_id and user_id are unique in emails table
- signup_action is either 'Verified' or 'Not Verified'
- All dates are in valid datetime format
- Each email_id in texts table exists in emails table
Visualization
Tap to expand
Understanding the Visualization
1
User Signs Up
User creates account and receives verification email
2
Second Day Check
We look for verification actions exactly 1 day later
3
Filter Verified
Only count successful 'Verified' actions
4
Collect Results
Return user IDs who verified on day 2
Key Takeaway
๐ฏ Key Insight: Use INNER JOIN with date arithmetic (DATEDIFF) to efficiently find users who verified exactly 1 day after signup in a single query
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code