22
Views
2
Comments
Solved
Cannot use join in Aggregate from two different database.

Hi all,
Thankyou all in advance for your your valuable feedback!

I recently faces an error showing "The Aggregate cannot join data from multiple databases"
I was trying to use an aggregate where i have taken one normal table and one other table that is from an external database.
I have checked few similar posts on forum, but still I wanted to discuss this in depth to have more idea about this.


With all of your help and replies I can understand this better.

Thankyou!


2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello Ayushi,

Hope you're doing well.

When you use an Aggregate in Service Studio, the platform automatically generates a SQL query behind the scenes. However SQL queries cannot be executed across two separate physical databases, that's why you're getting this error.


There are some possible workarounds for your use case, for example:

1) Create two separate Aggregates, one to fetch the data from the external database and another to fetch the data from the OutSystems database. After that you can use logic to join the results.

2) Create a staging / synchronization table in the OutSystems database to store the data from the external database. Basically you'll have faster queries, but you'll end up with duplicated data and you have to sync it if there are changes in the source system.


Let me know if you have any additional questions.


Kind regards,

Rui Barradas

2025-12-22 13-50-43
Sherif El-Habibi
Champion

Hi Ayushi,

In OutSystems, it’s not possible to directly join two entities from different data sources. Confirming what Rui mentioned, you can use an approach like: 

Sync Data Using a Timer (Batch Job)

  1. Use a timer to fetch and insert the data from the external source into a separate entity created in Service Studio.
  2. Once the data is inserted, you can handle the logic to combine or process the data from those entities as needed for example, by using an aggregate to join the two entities, as they are now both read as internal sources regardless of where the data came from.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.