Welcome to the SQL screen.
The question is on your right: Remove Duplicate Daily Search Queries. Read through the requirements and the one table first.
Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?
You are given a daily search log from TELUS Digital Search and need to clean duplicate search events. Write a PostgreSQL query that identifies duplicate rows for the same user_id, search_query, and calendar day, keeps the earliest event for each duplicate set, and removes the rest from the table.
Treat rows with the same user, same exact search text, and same date portion of searched_at as duplicates. Ignore rows where search_query is NULL or an empty string. Your result should show which rows would be deleted before the delete is executed.
| Column | Type | Description |
|---|---|---|
| log_idPK | INT | Primary key for each search log row |
| user_id | INT | Identifier of the user who performed the search |
| search_query | VARCHAR(255) | Raw search text entered by the user |
| searched_at | TIMESTAMP | Timestamp when the search event occurred |
| surface | VARCHAR(100) | TELUS Digital product surface where the search was performed |