When working with SuiteQL to analyze Purchase Orders, you may want to include additional information about related Entities (e.g., Vendors) and Employees (e.g., Sales Reps). However, not all Purchase Orders are associated with an Employee, so it’s important to structure your joins correctly.
This guide demonstrates how to build a SuiteQL query that pulls Purchase Orders along with:
- The Entity (Vendor) information — always required.
- The Employee information — if available.
INNER JOIN vs LEFT OUTER JOIN:
- INNER JOIN (Entity): Ensures that only transactions with a valid associated entity are returned. This is appropriate for the Entity join, as all Purchase Orders are expected to have one.
- LEFT OUTER JOIN (Employee): Allows transactions to be returned even if no Employee is associated — which is common for many Purchase Orders.
Sample Query
SELECT
Transaction.TranID,
Transaction.ID AS InternalID,
Transaction.TranDate,
Transaction.TranDisplayName AS TransactionName,
BUILTIN.DF( Transaction.Type ) AS Type,
BUILTIN.DF( Transaction.Status ) AS Status,
BUILTIN.DF( Transaction.Entity ) AS Entity,
BUILTIN.DF( Transaction.Employee ) AS Employee,
BUILTIN.DF( Entity.Type ) AS EntityType,
BUILTIN.DF( Entity.Phone ) AS EntityPhone,
Employee.Title AS EmployeeTitle,
Employee.Phone AS EmployeePhone,
Employee.Email AS EmployeeEmail
FROM
Transaction
INNER JOIN Entity ON
( Entity.ID = Transaction.Entity )
LEFT OUTER JOIN Employee ON
( Employee.ID = Transaction.Employee )
WHERE
Transaction.Type='PurchOrd'
This query:
- Retrieves all Purchase Order transactions.
- Joins to the Entity table to return details such as type and phone number.
- Optionally joins to the Employee table, returning their contact info only if the PO has an associated Employee