Most Searched Query
Which search query has been submitted the most times, and how many times?
- Aggregation
- Sorting
- Top-N
Challenge brief
Understand the request
Search Trends is monitoring trending queries and needs to surface the single most-repeated search term for a trend report.
Return query_text, cnt in the declared deterministic order.
Return
- query_text
- cnt (count of occurrences)
Constraints
- Return exactly one most-submitted query
- Break count ties alphabetically by query text
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
search_queries
query_idINTEGERuser_idINTEGERquery_textVARCHAR(200)search_dateDATE
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
First determine how often every query text appears.
Hint 2
The requested leader is the first row after descending frequency.
Hint 3
Add query text as the stable tie-break before limiting the result.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT query_text, COUNT(*) AS cnt FROM search_queries GROUP BY query_text ORDER BY cnt DESC, query_text LIMIT 1Why this works
All 42 queries are distinct — each query_text appears exactly once, so cnt = 1 for all rows. LIMIT 1 returns one row. The ORDER BY is cnt DESC — with all counts equal, the engine returns an arbitrary row. In this dataset it returns 'yoga classes'.
Success check
One stable query leader, with alphabetical tie handling
Expected result
Use this output to verify values, aliases, ordering, and row count.
| query_text | cnt |
|---|---|
| privacy controls | 2 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Microsoft
Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics SQL practice.
Netflix
Independent Netflix-style streaming, subscription, catalog, ratings, and engagement SQL practice.
Return to the complete interview preparation experience.