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
Count Entity Relationships Including Zero Matches
00:00
5 left

Count Entity Relationships Including Zero Matches

MediumSQL · PostgreSQL

Problem

Model the tables for a given scenario.

Define a normalized relational model that stores scenarios, their entities, and relationships between entities. Then write a query that reports every entity, including entities with no relationships.

Output

  1. One row per entity with scenario_name, entity_name, and relationship_count
  2. Include entities with zero relationships
  3. Order by scenario_name, then entity_name ascending

Schema

scenario_definitions
ColumnTypeDescription
scenario_idPKINTUnique scenario identifier
scenario_nameVARCHAR(100)Name of the modeled scenario
scenario_statusVARCHAR(20)Optional lifecycle status
scenario_entities
ColumnTypeDescription
entity_idPKINTUnique entity identifier
scenario_idINTScenario containing the entity
entity_nameVARCHAR(100)Entity name
primary_key_nameVARCHAR(100)Modeled primary key attribute name
scenario_relationships
ColumnTypeDescription
relationship_idPKINTUnique relationship identifier
source_entity_idINTEntity at the source end
target_entity_idINTEntity at the target end
relationship_nameVARCHAR(100)Name of the relationship
relationship_typeVARCHAR(30)Optional cardinality classification
Tablesscenario_definitionsscenario_entitiesscenario_relationships
Interviewer

Your question is Count Entity Relationships Including Zero Matches. 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.