Reported September 2026
Mygate

Users Active in Both January and February

Reported by candidates from Mygate's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Mygate OA. Under 2s to a working solution.
Founder's read

Mygate reported this SQL question in September 2026, and the whole thing hinges on one idea: a set of distinct users per month, then an intersection. If your OA invite is sitting there, this is the kind of query you can write in under five minutes once you see the shape. The activity table has event_id, user_id and activity_date. You need every user with at least one event in January 2025 and one in February 2025, sorted by user_id. If you blank on the syntax, StealthCoder runs invisibly during the live OA as a safety net.

The problem

The activity table records user activity events. Each row counts as one activity, and activity_date is a calendar date with no time or timezone conversion.
Find every user who has at least one activity in January 2025 and at least one activity in February 2025. Return one user_id row per qualifying user, sorted by user_id in ascending order.
Repeated events on the same date count as activity, but must not create duplicate result rows. Activity outside those two months, including the same months in another year, does not count.

Tables
activity: event_id PK (Integer), user_id (Integer), activity_date (Date)

Constraints
The table contains between 0 and 10^4 rows.
event_id is unique and between 1 and 10^9.
user_id is an integer between 1 and 10^9.
activity_date is a valid date between 2020-01-01 and 2030-12-31.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that you need two conditions on the same user across different rows, so a single WHERE can't do it. Three clean ways work. First, GROUP BY user_id with a HAVING clause that checks both months using conditional logic, like SUM(activity_date >= '2025-01-01' AND activity_date < '2025-02-01') > 0 and the same for February. Second, filter to the two-month window, then HAVING COUNT(DISTINCT month) = 2. Third, self-join distinct January users to distinct February users. The common pitfall is duplicates. Repeated events on the same date must not produce repeated rows, so use DISTINCT or GROUP BY. The other pitfall is the year. Use full date ranges, not MONTH() alone, or January 2024 will sneak in. Add ORDER BY user_id ascending. If your mind goes empty mid-OA, StealthCoder reads the schema on screen and hands you the query as a hedge.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Users Active in Both January and February cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Mygate's OA.

Mygate reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Users Active in Both January and February FAQ

How hard is the Mygate January and February users question really?+

Easy to medium. It's a standard SQL pattern: find entities present in two conditions across different rows. If you know GROUP BY with HAVING, or a self-join, you're done fast. The traps are duplicates and the year filter, not the logic.

What's the trick to solving it?+

Restrict to January and February 2025, group by user_id, and require both months to appear. Either count distinct months and demand 2, or use two conditional sums in HAVING. One WHERE clause alone can't check two different rows.

How do I avoid duplicate user_id rows?+

Group by user_id, or select DISTINCT in each subquery before joining. Repeated events on the same date are valid activity but must collapse to one result row per user. A raw join of the activity table to itself would multiply rows, so dedupe first.

Should I use MONTH() or date ranges?+

Use date ranges like activity_date >= '2025-01-01' and activity_date < '2025-03-01'. MONTH() alone ignores the year, so January 2024 or February 2026 would count wrongly. The problem says other years don't count, so the year matters.

How do I prepare for this in 48 hours?+

Write the HAVING version and the self-join version from memory. Then test edge cases: empty table, a user with only January, duplicate same-day events, and January 2024 rows. Finish with ORDER BY user_id. That covers nearly every variant of this pattern.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Mygate.

OA at Mygate?
Invisible during screen share
Get it