Skip to main content

Connecting Tables - Joins and Relationships

Set up table joins for multi-table queries using relationships. Connect orders to customers, order lines to orders.

What You're Trying to Do

Your data is in separate tables and you want Zoë to answer questions that span multiple tables.

Quick Solution (5 minutes)

Define a relationship on your model file — this is the recommended way to set up joins.

Step 1: Identify Your Key Fields

Most common patterns:

  • Orders → Customers: customer_id or customer_email

  • Order Lines → Orders: order_id

  • Events → Users: user_id or email

Step 2: Add a Relationship to Your Model File

In your model file (for example models/<model>.yml), add:

relationships:
- from_table: order_lines
join_table: orders
relationship: many_to_one # many_to_one (default) | one_to_one | one_to_many | many_to_many
join_type: left_outer # left_outer (default) | inner | full_outer
sql_on: ${order_lines.order_id} = ${orders.order_id}

Obvious foreign-key-to-primary-key joins (matching column names on both sides) usually don't need to be defined explicitly — Zoë can often infer them. Define a relationship when the join is non-obvious, uses a non-default cardinality or join type, or spans multiple columns.

Step 3: Deploy and Test

Deploy your change from Context Manager, then ask Zoë: "Show me customers and their total orders"

Getting data from multiple tables? You're all set! Zoë can now answer questions that span your connected tables.

About the legacy identifiers pattern

Older workspaces may still define joins using a identifiers block on the view (type: primary / type: foreign) inside a topic. This pattern still works but is no longer recommended for new joins — use relationships on the model file instead. Topics and identifiers are retained for backward compatibility only.

Still Need Help?

Complete Guide For detailed join configuration and advanced patterns → Relationships and Data Modeling

Ask Zoë Directly Try asking: "What tables can be joined together?" to see your current join graph

Contact Support If joins aren't working or you're seeing duplicate data → Contact Support with "Table Join Issue" and include:

  • The tables you're trying to connect

  • The key fields that should link them

  • Example of what you're trying to query

Related Quick Guides

Did this answer your question?