# Largest Opportunity per Account

**Type:** SOQL · **Difficulty:** Hard · **Topics:** Nested Subquery, LIMIT, Semi-Join

Practice this problem interactively (write and run your SOQL against realistic data): https://www.forcechallenges.com/problems/largest-opportunity-per-account

## Problem

**Scenario**
The VP of Sales wants a one-line view of each customer: the single biggest deal the company has on file for it. This helps her prepare executive conversations without scrolling through every Opportunity.

**Task**
Write one SOQL query on `Account` that:
1. Returns only Accounts that have at least one Opportunity with a non-null `Amount`.
2. For each returned Account, includes a child list with **only its largest Opportunity** (highest `Amount`), showing `Name` and `Amount`.
3. Ignores Opportunities whose `Amount` is null when picking the largest.

**Expected output**
One row per qualifying Account with `Id`, `Name` and a nested `Opportunities` list that contains exactly one record with `Name` and `Amount`. Row order does not matter.

**Example**
- Acme has Opportunities of 100,000, 450,000 and 300,000. It is returned with only the 450,000 Opportunity.
- Globex has one Opportunity with a null Amount. It is excluded.
- Initech has no Opportunities. It is excluded.

## Constraints

Use one query on Account with a child subquery on the Opportunities relationship that uses ORDER BY Amount DESC and LIMIT 1. Ignore Opportunities whose Amount is null, and do not return Accounts that have no Opportunity with an Amount.

---
Source: ForceChallenges · last updated 2026-10-23
