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
Reducing Unnecessary Database Hits
00:00
5 left

Reducing Unnecessary Database Hits

MediumSQL · PostgreSQL

Problem

What are the primary strategies for reducing unnecessary database hits?

Demonstrate the set-based approach with one PostgreSQL query that retrieves active Depop listings, seller usernames, and whether user 1 has liked each listing. Include listings even when seller or like data is missing.

Output

  1. One row per active listing.
  2. Columns: listing_id, listing_title, seller_username, liked_by_user, liked_at.
  3. Sort by newest created_at, then descending listing_id.

Schema

users
ColumnTypeDescription
idPKINTUser identifier
usernameVARCHAR(80)Depop username
is_activeBOOLEANWhether the account is active
listings
ColumnTypeDescription
idPKINTListing identifier
seller_idINTUser who created the listing
titleVARCHAR(150)Listing title
statusVARCHAR(20)Listing lifecycle status
created_atTIMESTAMPListing creation timestamp
listing_likes
ColumnTypeDescription
idPKINTLike identifier
listing_idINTLiked listing
user_idINTUser who liked the listing
created_atTIMESTAMPTime the like was created
Tableslistingsuserslisting_likes
Interviewer

Your question is Reducing Unnecessary Database Hits. 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.