# Accounts and Their Open Opportunities

**Type:** SOQL · **Difficulty:** Hard · **Topics:** Parent-to-Child, Nested Subquery, Semi-Join

Practice this problem interactively (write and run your SOQL against realistic data): https://www.forcechallenges.com/problems/accounts-with-open-opportunities

## Problem

**Scenario**
Sales managers want a daily list of customers with live deals, showing exactly which deals are still in play and which are the biggest. Customers with nothing open should not clutter the list.

**Task**
Write one SOQL query on `Account` that:
1. Returns only Accounts that have at least one **open** Opportunity (`IsClosed = false`).
2. Includes for each Account a child list of its **open** Opportunities only, showing `Id`, `Name` and `Amount`, sorted by `Amount` **highest first**.
3. Sorts the Accounts by `Name` ascending.

**Expected output**
One row per Account with `Id`, `Name` and a nested `Opportunities` list of `Id`, `Name` and `Amount`. Closed Opportunities must not appear in the child list.

**Example**
- Acme has open deals of 100,000 and 300,000 and a Closed Won deal of 900,000. It is returned with the deals listed as 300,000 then 100,000 (the won deal is not shown).
- Globex has only a Closed Lost deal. It is excluded.
- Initech has no Opportunities. It is excluded.

## Constraints

Use one query on Account with a child subquery on the Opportunities relationship and a semi-join (Id IN) on open Opportunities. Apply IsClosed = false in both the subquery and the semi-join. Sort the child list by Amount descending and the Accounts by Name ascending.

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