Skip to content

Include child records in queries

Fetch child records alongside a parent in a single HOQS query, optionally filtered, sorted, and nested.

The relationship name comes from the lookup’s toInverseKey — for example, if Contact has a lookup to Account with toInverseKey: "contacts", you can include contacts when querying accounts:

SELECT name, industry FROM core.Account
INCLUDE contacts
LIMIT 10

Each Account in the result has a contacts array with the matching child records.

2. Filter, select fields, sort, and limit within the INCLUDE

Section titled “2. Filter, select fields, sort, and limit within the INCLUDE”
SELECT name FROM core.Account
INCLUDE contacts (firstName, email) WHERE status = 'active' ORDER BY lastName ASC LIMIT 5
LIMIT 10
SELECT name FROM core.Account
INCLUDE contacts
INCLUDE opportunities WHERE stage = 'Closed Won' LIMIT 10
LIMIT 10

This returns Accounts with their Contacts, and each Contact carries its own Opportunities. Nesting depth is limited to 3 levels.

Check that each parent record in data carries the included relationship as a nested array, and that any WHERE/ORDER BY/LIMIT you added inside the INCLUDE clause is reflected in that array (not the top-level result set).