# Cross-database queries

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/idea/2026.3/llms.txt).

Procedure: Enable the Database Tools and SQL plugin

This functionality relies on the  Database Tools and SQL plugin, which  is bundled and enabled in IntelliJ IDEA   by default. If the relevant features are not available, make sure that you did not disable the plugin.

> **Note:**
> Database Tools and SQL functionality support is limited in IntelliJ IDEA without the Ultimate subscription.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Find the Database Tools and SQL plugin and click Enable.

In IntelliJ IDEA, you can query data across different databases and view results directly without copying the data beforehand.  The IDE provides a dedicated Workspace data source that acts as an intermediary between IntelliJ IDEA and the databases you query. Use its query consoles to write and execute SQL queries with `Ctrl+Space` (Windows), `⌃ Space` (macOS), `⌃ Space` (IntelliJ IDEA Classic (macOS)), `⌃ Space` (macOS System Shortcuts), `Ctrl+Space` (XWin), `Ctrl+Space` (GNOME), `Ctrl+Space` (KDE), `Alt+/` (Emacs), `Ctrl+Space` (Sublime Text), `⌃ Space` (Sublime Text (macOS)), `Ctrl+Space` (Visual Studio), `⌃ Space` (Visual Studio (macOS)), `Ctrl+Space` (NetBeans), `Ctrl+Space` (Eclipse), `⌃ Space` (Eclipse (macOS)) code completion and a [special syntax](#syntax).

## Workspace data source

The Workspace data source is based on [DuckDB](duckdb.html) and creates an in-memory DuckDB database by default. Each project can have one Workspace data source, with as many query consoles as needed.

![The Workspace data source settings](https://resources.jetbrains.com/help/img/idea/2026.3/db_workspace_data_source_settings.png)

Procedure: Create the Workspace data source

* On the   Database   tool window  toolbar, click ![the Add icon](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.general.add.svg) Add and select ![the Workspace Data Source icon](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.nodes.homeFolder.png) Workspace Data Source.

IntelliJ IDEA will add the data source to the list in   Database   tool window  and open its default query console automatically.

![The Workspace data source settings](https://resources.jetbrains.com/help/img/idea/2026.3/db_workspace_data_source_menu.png)

## Syntax

In the Workspace data source query console, you can reference tables from other data sources using the following syntax:

* To reference a table directly, specify its data source and table name. Add the database and schema when needed: ``` #data_source[.database.schema].table ```

* To filter a table, add `#filter(...)` to the reference: ``` #data_source[.database.schema].table.#filter('condition') ```

* You can also use `#query(...)` to run a query against a data source: ``` #data_source[.database.schema].#query('query') ```

In `#filter(...)` and `#query(...)`, you can use `$$...$$` dollar-quoted strings instead of single quotes: `#filter($$condition$$)` and `#query($$query$$)`.

Type `#` to select a data source using code completion.

![Code completion in cross-database queries](https://resources.jetbrains.com/help/img/idea/2026.3/db_cross_database_code_completion.png)

## Examples

Here are a few examples of the syntax in use with PostgreSQL and MySQL data sources and the respective Sakila databases:

* Filter rows in a referenced table: ``` SELECT * FROM #PostgreSQL.guest.public.customer.#filter('customer_id > 100'); ``` ![Example of a cross-database query filtering rows in a referenced table](https://resources.jetbrains.com/help/img/idea/2026.3/db_cross_database_query_filter.png)

* Run a query against a referenced data source: ``` SELECT * FROM #PostgreSQL.guest.public.#query($$ SELECT customer_id, amount FROM payment WHERE amount > 5 $$); ``` ![Example of a cross-database query running a query against a referenced data source](https://resources.jetbrains.com/help/img/idea/2026.3/db_cross_database_query_query.png)

* Join data from PostgreSQL and MySQL data sources: ``` SELECT c.first_name, c.last_name, p.amount FROM #PostgreSQL.guest.public.customer c JOIN #MySQL.sakila.payment p ON c.customer_id = p.customer_id; ``` ![Example of a cross-database query joining data from PostgreSQL and MySQL data sources](https://resources.jetbrains.com/help/img/idea/2026.3/db_cross_database_query_join.png)

