# Federated Query

> One SQL query that reads from more than one system.

**Field:** Data Engineering  
**Category:** Analytics & BI  
**Also known as:** Query Federation, Data Federation, Cross-Database Query

## Think of it like

It is like one shopping list that a helper fills from three different shops. You get one bag back.

## Definition

A federated query reads from more than one data system in a single SQL statement. One part might come from a PostgreSQL database and another from files in a data lake. The engine sends each part to its source, then joins the results. No data is copied ahead of time. It is handy for one-off joins, but it is slower than querying data kept in one place.

## Example

Finance wants to join this morning's customer list with last year's orders. A federated query does it now, with no pipeline.

## Example code

```sql
SELECT c.name, SUM(o.total) AS spent
FROM postgresql.public.customers AS c
JOIN hive.sales.orders AS o ON o.customer_id = c.id
GROUP BY c.name;
```

One query, two systems. Customers come from PostgreSQL, and orders come from the data lake.

## Why it matters

It answers a question that spans two systems today. You do not wait for a pipeline to copy the data.

## Common mistake

Building daily reports on it. Each run reads both systems again and can slow the live database. Copy the data instead.

## Three principles

- **Many sources.** One query, several systems.
- **No copy first.** Data stays where it is.
- **Good for one-offs.** Slower than one store.

## Related terms

- [Trino](https://learn.benibix.com/term/data/trino)
- [Query Engine](https://learn.benibix.com/term/data/query-engine)
- [Data Integration](https://learn.benibix.com/term/data/data-integration)
- [SQL Join](https://learn.benibix.com/term/development/join)
- [PostgreSQL](https://learn.benibix.com/term/development/postgresql)

![One SQL query goes into a query engine made of a coordinator and three workers. Connectors lead from the workers to three places the data lives: a PostgreSQL database, Parquet files in a data lake and a Kafka topic. The answer comes back as one table.](https://learn.benibix.com/diagrams/query-engine.svg)

---

Source: https://learn.benibix.com/term/data/federated-query
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
