Here’s the complete solution for joining standard and custom ERP tables in ad-hoc reporting API queries:
Column Aliasing in Joins: Use explicit table.column notation in the fields array:
{
"fields": [
"orders.id",
"orders.order_date",
"custom_orders_ext.priority_score"
]
}
Never use bare column names like id when joining multiple tables. The API won’t auto-resolve ambiguity like some SQL engines do.
Custom Table Schema Review: First, verify your custom table’s schema location:
GET /api/metadata/tables/custom_orders_ext
// Check response for schema: "custom_schema" or "default"
If custom tables are in a non-default schema, use full qualification:
"fields": ["custom_schema.custom_orders_ext.priority_score"]
API Query Payload Structure: Structure joins using the joins array with explicit conditions:
{
"from": "orders",
"fields": [
"orders.id",
"orders.order_date",
"custom_orders_ext.priority_score"
],
"joins": [
{
"table": "custom_orders_ext",
"type": "LEFT",
"on": {
"left": "orders.id",
"right": "custom_orders_ext.order_id"
}
}
]
}
Key points: specify join type (INNER, LEFT, RIGHT), use table.column format in the on condition, and include schema qualification for custom tables if needed. For multiple joins, add additional objects to the joins array. Each join builds on the previous result set.
Best practice: review your custom table naming conventions. If you’re frequently joining custom extensions to standard tables, consider prefixing custom column names (e.g., ext_id, ext_priority) to avoid ambiguity. This reduces the need for verbose table qualification in every query. With proper payload structure and schema qualification, your joins should execute successfully.