AnalystPath

Longest Consecutive Login Streak

SQLHardSenior level~15 min

Problem

**[Widely asked at gaming and social platforms]**

Find the **longest unbroken daily login streak** for each user.
A streak is a sequence of consecutive calendar days where the user logged in.
If a user skips even one day, the streak resets.

Return `user_id` and `max_streak`, ordered by user_id.

Tables

Example rows — the live problem includes the full dataset.

login_log
log_iduser_idlogin_date

Expected output

Your answer should return 2 rows with the columns user_id, max_streak.

Starter code (SQL)

SELECT *
FROM login_log;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions