149
Views
10
Comments
How can I combine two SQL Queries?

I Have two SQL's in a preparation. 

SQL 1 = A_ID | Age |

SQL 2 = A_ID | Name|

I want to display 

A_ID | Age | Name|

I'm okay wither either joining them in the preparation or any other way to get the display to look the way I need it to.

2023-11-07 18-53-22
José Rodrigues

Hey Pedro,

Can you give some extra details on what is exactly your objective?
Do you want the output of your SQL to have both the attribute Age and the attribute Name?

2024-07-05 14-16-55
Daniël Kuhlmann
Ā 
MVP

Hi,

Just use an aggregate and join it on A_ID.

You don't need two SQL, one aggregate is enough.

https://success.outsystems.com/documentation/11/reference/outsystems_language/data/handling_data/queries/supported_join_types/

Regards,

Daniel

2021-10-01 12-43-46
N_SG

Hi @Pedro Torres,
You need to write your query something like below:

SELECT {SQL1}.[A_ID], {SQL1}.[Age], {SQL2}.[Name]
FROM {SQL1}
INNER JOIN {SQL2} ON {SQL1}.[A_ID]= {SQL2}.[A_ID]

You can call it wherever your bussiness is required

Hope it helps

Regards
N_G

2024-07-05 14-16-55
Daniël Kuhlmann
Ā 
MVP

This use case is so simple an aggregate should be used, not an SQL 

2025-10-18 11-13-53
Ramesh subramanian

Hi Pedro Torres, 

Just join two or more tables on one Join Condition in Aggregate.

Please check this link for an example.

https://www.outsystems.com/forums/discussion/47830/how-to-join-two-or-more-tables-on-one-join-condition-in-aggregate/


Like join with A_ID 

Thanks,

Ramesh

UserImage.jpg
Greg Adams

Is there some complication that you haven't mentioned?

If all you want is to get The ID, Age, Name from every record that can be done simply using an aggregate.

The aggregate can be edited to produce the columns in the order you require.


But if this is part of something more complicated where you need to use SQL that is also fairly simple if the age & name are in the same table. You just have to list the 3 things between SELECT & From

SELECT [ID], [Age],[Name] FROM

Your output has to be defined to fit those three items by using the same structure.

Or is there something more complicated that you are trying to do?

2025-09-25 14-38-22
Lokesh Kumar Yadav

Hi Perado,

Try to use the left join you can get this columns that you want 


2023-03-03 06-59-12
Reemali patil

Hi Pedro Torres,

Try to write subqueries in SQL wigdet to get data instead of aggregate.

Thanks & Regards

Reemali.


2022-07-03 17-24-08
Sourabh sharma

Hi @Pedro Torres 

As I have analysis on your asked question have seen Name and age both are coming from same entity A_ID , why you want to use Two SQLs it can be Done using one only. like this..

Note: You don't need two SQLs , one aggregate/Sql is enough . 

---------

IF you have Two Different Entities.!


1.Create a structure for required output.

2.Write the join as given in IMAGE.

3. Test Value as given IMAGE.

Hope you understand 


Kind regards

Sourabh

2024-07-05 14-16-55
Daniël Kuhlmann
Ā 
MVP

Hi @pedro Torres

Please mark one or more replies as solution, multiple times solutions are provided already.

Kind regards,

Daniel

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.