Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Duplicates Across Locations
00:00
5 left

SQL Duplicates Across Locations

MediumSQL · PostgreSQL

Problem

How would you write a SQL query to find duplicate product listings across multiple retail store locations?

Assume duplicate listings are active listings for the same product appearing at two or more distinct store locations. Return only products with valid product and store records.

Output

  1. One row per duplicated product, with product_id, product_name, brand, location_count, and locations.
  2. Include the distinct store names in alphabetical order.
  3. Order by location_count descending, then product_id ascending.

Schema

product_listings
ColumnTypeDescription
listing_idPKINTEGERUnique listing identifier
product_idINTEGERReferenced product identifier
store_idINTEGERReferenced retail store identifier
listing_statusVARCHAR(20)Listing state, such as active or inactive
retail_stores
ColumnTypeDescription
store_idPKINTEGERUnique retail store identifier
store_nameVARCHAR(120)Retail store name
cityVARCHAR(80)Store city
products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(150)Product display name
brandVARCHAR(100)Product brand
Tablesproduct_listingsretail_storesproducts
Interviewer

Your question is SQL Duplicates Across Locations. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.