Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Remove Duplicate Daily Search Queries

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

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 need to log in / sign up to run or submit.

Problem

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.

Schema

daily_search_log
ColumnTypeDescription
log_idPKINTPrimary key for each search log row
user_idINTIdentifier of the user who performed the search
search_queryVARCHAR(255)Raw search text entered by the user
searched_atTIMESTAMPTimestamp when the search event occurred
surfaceVARCHAR(100)TELUS Digital product surface where the search was performed
Tablesdaily_search_log
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results