Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write a Query for Repeated Rows

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Write a Query for Repeated Rows. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Zomato’s data quality team wants to identify repeated order-item records that may have been ingested more than once. Treat rows as repeated when all business columns match, excluding the unique order_item_id.

Write a PostgreSQL query to find these repeated rows and enrich the results with the restaurant name.

Requirements

  1. Group records by restaurant, customer, item, quantity, price, and order timestamp.
  2. Return only groups containing at least two rows, including a duplicate count.
  3. Return the matching order_item_id values as a comma-separated list, ordered numerically.
  4. Preserve records whose restaurant ID is not present in the restaurant table.

Schema

order_items
ColumnTypeDescription
order_item_idPKINTUnique order-item record ID
restaurant_idINTReferences restaurants.restaurant_id
customer_idINTCustomer identifier
item_nameVARCHAR(100)Ordered menu item
quantityINTQuantity ordered
unit_priceDECIMAL(10,2)Price per item
ordered_atTIMESTAMPOrder creation timestamp
restaurants
ColumnTypeDescription
restaurant_idPKINTUnique restaurant identifier
restaurant_nameVARCHAR(150)Restaurant display name
Tablesorder_itemsrestaurants
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results