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
Left Join Example
00:00
5 left

Left Join Example

EasySQL · PostgreSQL

Problem

Give me an example of a left join in SQL.

Write a PostgreSQL query using the provided tables to return every account and any matching support tickets. Accounts without tickets must still appear, with NULL ticket fields.

Output

  1. One row per matching account and ticket, plus one row for each account without a ticket
  2. Columns: account_id, account_name, ticket_id, subject
  3. Order by account_id ascending, then ticket_id ascending with NULL ticket IDs last

Schema

customer_accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
account_nameVARCHAR(100)Account display name
account_statusVARCHAR(20)Current account status
support_tickets
ColumnTypeDescription
ticket_idPKINTUnique ticket identifier
account_idINTAccount associated with the ticket
subjectVARCHAR(150)Ticket subject
priorityVARCHAR(20)Ticket priority
Tablescustomer_accountssupport_tickets
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.