# Write a SOQL query to fetch all OpportunityLineItem records along with the Product Name (Product2.Name), Pricebook Name (PricebookEntry.Pricebook2.Name), and Account Name (Opportunity.Account.Name).

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Accenture, Deloitte, Cognizant · **Tags:** soql, scenario, child-to-parent, multi-level

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-all-opportunitylineitem-records-along-with-the-product-name-product2-name

## Answer

Traverse from the line item to each related record through relationship names.

```soql
SELECT Id, Quantity, UnitPrice,
       Product2.Name,
       PricebookEntry.Pricebook2.Name,
       Opportunity.Account.Name
FROM OpportunityLineItem
```
This is a multi-level child-to-parent query, well within the 5-level limit.

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