Get startedGet started for free

Defining relationships

1. Defining relationships

Most business questions span multiple tables. Let's learn how relationships enable cross-table queries.

2. Why relationships matter

Genie CAN infer relationships if column names match perfectly, like customer_id in two tables, but relying on inference is a gamble.

3. When inference fails

Inference fails in two scenarios: first, ambiguous column names. Multiple ID columns like creator_id, updater_id, and owner_id mean Genie doesn't know which connects to Users. Second, naming discrepancies. One table uses client_no, another uses customer_id, and Genie sees them as unrelated islands. Defining explicit relationships is like giving Genie a GPS map instead of letting it wander around looking for street signs. It ensures complex questions follow your business rules, not guesses.

4. How Genie uses joins

Let's look at what happens behind the scenes. We'll ask "Show me transaction totals by customer region." This question needs data from transactions, customers, and franchises tables. Genie looks at the defined relationships, identifies the correct join keys, and generates proper SQL with the right JOIN clauses.

5. Defining a relationship

Defining a relationship isn't writing code. It's selecting two tables and "pointing" at the linking columns. In the Join Configuration UI, you choose the source and target tables, then specify which columns connect them. For example, sales_transactions.customerID joins to sales_customers.customerID. You can also set the join type: One to One, One to Many, Many to One, or Many to Many. Most business analytics use One to Many because it naturally supports grouping, summarizing, and hierarchical reporting.

6. Cross-table query

Let's run a cross-table query: "What are the email addresses of our top 5 spenders?" This touches sales_transactions, sales_customers, and possibly sales_franchises. Watch the generated SQL. Genie correctly joins the tables, aggregates spend, and pulls the email addresses. Without explicit relationships, this query would fail.

7. Common relationship patterns

Business users often don't realize that a question like "Which customers in Chicago haven't visited us in 10 days?" requires a two-way or three-way handshake between tables. An entity-relationship diagram is essential for this; it makes these connections visible. Watch out for two common join mistakes: first, neglecting join direction and cardinality. Without defining One-to-Many, Genie might aggregate in ways that duplicate values, causing fan-out issues. Second, missing the bridge table. In Many-to-Many relationships, like Products and Orders, Genie needs the middle "Line Items" table, or it fails to connect the dots.

8. Let's practice!

Explore how relationships power cross-table queries. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.