Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query for Employees in Troy

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Query for Employees in Troy. Start with the requirements and the three tables on the right.

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.

Problem

Dynatrace uses employee and office records to support workforce views in its internal engineering systems. Write a PostgreSQL query that returns all employees assigned to an office in Troy.

Requirements

  1. Join employees to offices using office_id.
  2. Return only employees whose office city is exactly Troy.
  3. Include the employee's name, job title, office city, country, and department name. Preserve Troy employees even when their department is not assigned.
  4. Order the results by last name, then first name, and employee ID for deterministic output.

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
first_nameVARCHAR(60)Employee first name
last_nameVARCHAR(60)Employee last name
job_titleVARCHAR(120)Employee job title
office_idINTEGERAssigned office identifier
department_idINTEGEROptional department identifier
offices
ColumnTypeDescription
office_idPKINTEGERUnique office identifier
cityVARCHAR(80)Office city
countryVARCHAR(80)Office country
departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(120)Department name
Tablesemployeesofficesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results