To query related Salesforce records, choose syntax by direction: use dot notation to read parent fields from a child record, or a nested subquery to retrieve child records from a parent. The relationship must exist in your Salesforce schema, and relationship names—not necessarily object or field API names—determine what you write in the query.
Choose the query pattern by relationship direction
SOQL relationship queries follow defined Salesforce relationships; they are not arbitrary SQL joins. As Salesforce explains in its Relationship Queries reference, the queried objects must have a relationship. First identify which object should supply the top-level rows, then choose the matching pattern.
| What you need | Query from | Syntax | Result shape |
|---|---|---|---|
| Parent fields on each child record | Child object | Dot notation using the parent relationship name | Child rows with selected parent fields |
| Related child records for each parent | Parent object | Nested subquery using the child relationship name | Parent rows with nested child result sets |
Get parent fields from a child record
For a child-to-parent query, put the child object in the outer FROM clause and traverse to parent fields with dot notation. For example, a Contact can retrieve fields from its related Account:
SELECT Id, FirstName, Account.Name
FROM Contact
WHERE Account.Industry = 'Media'
Account.Name selects the parent Account’s name for each returned Contact. The filter Account.Industry = 'Media' also refers to the parent. Relationship paths can be used in fields and filters, as described in Salesforce’s Using Relationship Queries guidance.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
The path uses the parent relationship name exposed on the child, not simply an assumption based on a field label. This is especially important for custom fields, where the API field name and the relationship name differ.
Get child records from a parent
For a parent-to-child query, put the parent in the outer FROM clause and add a child subquery in parentheses. The subquery’s FROM uses the child relationship name. For Account and Contact, that name is Contacts:
SELECT Name,
(SELECT LastName FROM Contacts)
FROM Account
The query returns Account rows, each with a nested result set containing its matching Contacts. You can select child fields and apply a child-specific filter inside that subquery. For example:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
SELECT Name,
(SELECT LastName
FROM Contacts
WHERE CreatedBy.Alias = 'jsmith')
FROM Account
WHERE Industry = 'Media'
The outer WHERE filters Accounts; the subquery’s WHERE filters Contacts returned for each Account. Salesforce’s SOQL SELECT examples show relationship query patterns and filtering.
Free tools Windows power users keep installed
One-click scans. No signup required.
Understand the returned data shape
The outer query determines the records at the top level. Child-to-parent traversal adds selected parent fields to each child row. Parent-to-child traversal instead places a nested query result set on each parent record.
A simplified parent-to-child response is conceptually shaped like this:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Account: {
Name: "Acme",
Contacts: [
{ LastName: "Nguyen" },
{ LastName: "Patel" }
]
}
This is an illustration of the nesting, not literal JSON returned identically by every Salesforce API. When consuming results, handle the child query result as a collection associated with its parent rather than expecting one flat row per parent-child pair. See Salesforce’s Understanding Query Results reference.
Find the correct relationship name in your org
Relationship names are directional. A child-to-parent path uses the parent relationship name; a parent-to-child subquery uses the child relationship name. Salesforce documents the standard naming distinction in Understanding Relationship Names.
Recommended Free Tools
- Standard example: Account-to-Contact parent-to-child traversal uses
Contactsin the subquery, notContact. - Custom child-to-parent traversal: a custom lookup field whose API name ends in
__cis traversed using its relationship name ending in__r. - Custom parent-to-child traversal: use the configured child relationship name; do not assume it is the plural form of the child object’s name.
To verify names and confirm that a relationship is available to SOQL, inspect the target org’s metadata. Salesforce identifies describeSObjects() as the most reliable way to identify parent and child relationships; the Identifying Parent and Child Relationships reference covers this discovery process. The custom objects and fields guidance explains the __c/__r distinction.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
A relationship diagram alone is not proof that a particular relationship can be traversed in SOQL. Check the metadata for the org and package version where the query will run.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Check depth, API version, and execution context
Relationship limits depend on both query direction and how the query is executed. Salesforce’s current Understanding Relationship Query Limitations documentation specifies these limits:
| Limit | Documented allowance | Important qualification |
|---|---|---|
| Child-to-parent relationships in a query | Up to 55; custom objects allow up to 40 | Polymorphic fields can count more than once; repeated use of the same relationship counts as one. |
| Parent-to-child relationships in a query | Up to 20 | Applies to the documented relationship-query limits. |
| Child-to-parent path depth | Up to five levels | Confirm the queried relationships are exposed and supported in the execution context. |
| Parent-to-child path depth | Two levels or fewer through API v57.0; up to five from API v58.0 | The five-level allowance applies to REST, SOAP, and Apex query calls on standard and custom objects. It is not supported for big objects, external objects, Bulk API, or Bulk API 2.0. |
The API-version boundary is a practical deployment concern: a query that uses deeper parent-to-child traversal can fail when run through an older API version or an unsupported context. Verify the version and interface actually used by the application, integration, or job; do not infer support from the query syntax alone. Salesforce also documents additional external-object constraints, including up to four joins across external and other objects, possible additional round trips and latency, and restrictions on ordering and subquery results. Adapter and object conditions matter, so consult the applicable documentation before applying those external-object figures to a specific setup.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Troubleshoot a relationship query that fails
When a relationship query is rejected or returns a different shape than expected, check the issue in this order:
- Confirm the direction. If the outer
FROMis the child and you need parent fields, use a dot path. If it is the parent and you need child rows, use a nested subquery. - Verify the relationship name. Check the relevant object’s describe metadata. Use the parent relationship name for dot notation and the child relationship name in a subquery.
- Check custom API names. A custom lookup field ending in
__cis not the traversal name; parent traversal uses the associated relationship name ending in__r. - Confirm a SOQL relationship exists. SOQL does not permit an arbitrary join between unrelated objects.
- Check the path depth and relationship counts. Compare the query with the documented direction-specific limits, including the custom-object relationship count.
- Check API version and execution method. Deep parent-to-child traversal depends on API v58.0 or later and is unavailable in the stated unsupported contexts.
- Inspect the result as nested data when appropriate. A parent-to-child subquery produces a child result set on each parent, not a flat set of child rows.
For a focused example set, see Salesforce’s SOQL SELECT examples; for syntax, naming, and limit details, use the linked official relationship references above.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

