Query your sources

Last updated:

|Edit this page

To see all of the sources available to query, go to the data warehouse tab. This page shows all the external and PostHog tables you can query through SQL insights along with saved views. Click on any of the tables, and then click "Query" to open an SQL insight.

Data warehouse tab in PostHog app

Querying sources

To start with querying your sources:

  1. Choose a table and click "Query" or create a new SQL insight.
  2. If you didn't already, choose a table to query FROM like stripe_charge or hubspot_contacts
  3. Write your SQL query using your table like SELECT * FROM hubspot_contacts
  4. Click "Update and run" to see the results.
  5. Modify your query using SQL commands as needed to get the data you want like SELECT email FROM hubspot_contacts WHERE city = 'Brisbane'.
  6. Save your query.
Querying a source in PostHog

Combining data sources

Much of the power of the data warehouse comes from combining multiple sources, like your Stripe or Hubspot data with your product analytics data. Two of the easiest ways of doing this are WHERE IN and JOIN SQL commands.

For example, to get a count of events for your Hubspot contacts you can filter events.distinct_id by email FROM hubspot_contacts like this:

SQL
SELECT COUNT() AS event_count, distinct_id
FROM events
WHERE distinct_id IN (SELECT email FROM hubspot_contacts)
GROUP BY distinct_id
ORDER BY event_count DESC

You can also use a JOIN such as INNER JOIN or LEFT JOIN to combine data. For example, to get a count of events for your Stripe customers you can INNER JOIN on distinct_id and email like this:

SQL
SELECT events.distinct_id, COUNT() AS event_count
FROM events
INNER JOIN prod_stripe_customer ON events.distinct_id = prod_stripe_customer.email
GROUP BY events.distinct_id
ORDER BY event_count DESC

Questions?

Was this page useful?

Next article

Filtering, visualizing, and joining data

Once you link a source , your external data can be used alongside the rest of the PostHog. Visualizing Data synced to the data warehouse is available for use in insights, just as events and actions are. You can select your data warehouse data as a series in the dropdown when creating an insight. The main difference from events is that you must identify 3 fields from the data warehouse data to visualize it: ID: A field that corresponds to the ID of the element. Distinct ID: A field that…

Read next article