# How do you write a Parent-to-Child subquery on Standard Objects (Contacts) vs Custom Objects (Employees__r)?

**Topic:** Soql · **Difficulty:** Easy · **Asked at:** Infosys, Cognizant, HCL · **Tags:** soql, relationships, parent-to-child

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-you-write-a-parent-to-child-subquery-on-standard-objects-contacts-vs-custom-objects-employees-r

## Answer

Use a subquery in the SELECT list with the **child relationship name** (plural for standard objects, `__r` for custom).

```soql
SELECT Id, Name, (SELECT LastName, Email FROM Contacts) FROM Account
SELECT Id, Name, (SELECT Name, Salary__c FROM Employees__r) FROM Department__c
```
Results are nested lists: in Apex use `acc.Contacts` or `dept.Employees__r`. The relationship name comes from the lookup/master-detail field's Child Relationship Name setting.

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