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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
SQL Queries to Extract and Validate Data
00:00
5 left

SQL Queries to Extract and Validate Data

MediumSQL · PostgreSQL

Problem

How do you write queries to extract, join, and validate data at Best Buy?

Use the provided Best Buy order, order-item, and product data. Return completed orders and classify each order line according to whether its product reference, quantity, prices, and calculated total are valid.

Output

  1. One row per order item from completed orders.
  2. Columns: order_id, order_date, item_id, product_sku, product_name, quantity, recorded_unit_price, recorded_line_total, and validation_status.
  3. Include missing products and invalid lines, and order by order_id, then item_id.

Schema

best_buy_orders
ColumnTypeDescription
order_idPKINTUnique Best Buy order identifier
order_dateDATEDate the order was placed
statusVARCHAR(20)Order lifecycle status
best_buy_order_items
ColumnTypeDescription
item_idPKINTUnique order-item identifier
order_idINTOrder containing the item
product_skuVARCHAR(30)Referenced product SKU, when available
quantityINTQuantity purchased
unit_priceNUMERIC(10,2)Unit price recorded on the order
line_totalNUMERIC(10,2)Recorded extended price for the item
best_buy_products
ColumnTypeDescription
skuPKVARCHAR(30)Unique product stock-keeping unit
product_nameVARCHAR(100)Product display name
current_priceNUMERIC(10,2)Current catalog price
Tablesbest_buy_ordersbest_buy_order_itemsbest_buy_products
Interviewer

Your question is SQL Queries to Extract and Validate Data. 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.