# Errors With Service Health

> Error data, enriched with health context.

Canonical URL: <https://datadriven.io/problems/errors_with_service_health>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

For each error record, pair it with the corresponding service's current status, latency, and uptime from the service health table. Include the error ID, error type, message, service name, severity, count, first occurrence, service status, latency, and uptime.

## Worked solution and explanation

### Why this problem exists in real interviews

Joining error records with service health data is a common observability task. This tests basic INNER JOIN mechanics: identifying the correct join key and selecting columns from both tables.

---

### Break down the requirements

#### Step 1: Identify the join key

Both `err_tracks` and `svc_health` share `svc_name`. This is the natural join key.

#### Step 2: Write the JOIN

`JOIN svc_health ON err_tracks.svc_name = svc_health.svc_name` pairs each error with its service's health.

#### Step 3: Select requested columns

Pull error details and health metrics (status, latency, uptime) from both tables.

---

### The solution

**Inner join on service name**

```sql
SELECT e.err_id, e.err_type, e.message, e.svc_name,
       e.severity, e.count, e.first_at,
       s.status, s.latency, s.uptime
FROM err_tracks e
JOIN svc_health s ON e.svc_name = s.svc_name
ORDER BY e.err_id
```

> **Cost Analysis**
>
> If `svc_health` has one row per service, the optimizer uses it as the build side of a hash join. An index on `svc_health(svc_name)` guarantees fast lookup.

> **Interviewers Watch For**
>
> This is a basic join question. Getting the join key wrong or using CROSS JOIN is a red flag.

> **Common Pitfall**
>
> If some services in `err_tracks` have no match in `svc_health`, INNER JOIN drops those errors. Consider LEFT JOIN if you need all errors.

---

## Common follow-up questions

- What if some errors reference unknown services? _(Tests LEFT JOIN awareness.)_
- What if health has multiple rows per service (history)? _(Tests filtering to latest snapshot.)_
- How would you add error count per service? _(Tests window function or GROUP BY.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/errors_with_service_health)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.