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
Start free
SQL Join Types
00:00
5 left

SQL Join Types

MediumSQL · PostgreSQL

Problem

Can you explain the different types of joins in SQL and when you would use each?

Use the provided customers and orders tables to demonstrate the behavior of a join that preserves unmatched rows from both tables. Explain how INNER, LEFT, RIGHT, FULL OUTER, CROSS, and self joins differ.

Output

  1. One row per matched or unmatched customer and order relationship
  2. Columns: customer_id, customer_name, order_id, order_customer_id, and join_status
  3. Include unmatched rows from both tables and order by the coalesced customer identifier, then order_id

Output details

  • Sort the coalesced customer identifier and order_id in ascending order, placing NULL order_id values last.
  • Return NULL for unavailable customer or order fields on unmatched rows.
  • Use matched, customer_without_order, and order_without_customer as the exact join_status values.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer associated with the order
order_statusVARCHAR(30)Current order status
Tablescustomersorders
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.