Skip to main content

Joining tables

This page explains how RevenueBase data feed tables relate to each other, which keys to use for joins, and common pitfalls.

Relationship overview

  • Companies is the primary entity table for organizations.
  • Contacts (people) reference Companies via a foreign key (e.g., company_id).
  • Insights and Historical Experience can reference Contacts and/or Companies.
Document each relationship on the relevant table pages and summarize here.

Join keys

From tableTo tableJoin keyRelationship
ContactsCompaniescontacts.company_id = companies.idMany-to-one
InsightsContactsinsights.contact_id = contacts.idMany-to-one
InsightsCompaniesinsights.company_id = companies.idMany-to-one
Historical ExperienceContactshistorical_experience.contact_id = contacts.idMany-to-one
Use these keys in your JOIN conditions. Column names may differ in your real schema; adjust accordingly.

Example joins

Contacts to Companies (many-to-one):
SELECT c.id, c.email, co.name AS company_name
FROM contacts c
JOIN companies co ON co.id = c.company_id;
Include company rows with no contacts (LEFT JOIN):
SELECT co.name, c.email
FROM companies co
LEFT JOIN contacts c ON c.company_id = co.id;
Contacts with Insights:
SELECT c.email, i.insight_type, i.value
FROM contacts c
JOIN insights i ON i.contact_id = c.id;

Gotchas and best practices

  1. Cardinality — Contacts may have many rows per Company. Aggregating or limiting per entity can avoid duplicates in reporting.
  2. Nulls — Foreign key columns are usually non-null when the relationship is required; optional relationships may allow nulls. Check the Data dictionary and table pages.
  3. Performance — Join on indexed columns (typically primary and foreign keys). Large tables may require filters or limits during development.
  4. Pre-joined views — For common combinations (people + companies, or + insights), use Pre-Joined Tables instead of writing joins yourself.
For table-specific details, see Companies, Contacts, Insights, and Historical Experience.