Merge two query results / arrays / lists

Hi,

I’ve got a server side action that has two database queries from seperate tables, each generating an array/list, that are very similar. Examples below:

query1

[ 
{ id: 133, name: "john" },
{ id: 565, name: "joe" },
{ id: 399, name: "james" },
]

query2

[ 
{ id: 102, name: "tom" } ,
{ id: 382, name: "terry" },
{ id: 311, name: "tanya" },
]

How can I join these 2 queries/arrays/lists on server side to achieve the expected output below?
I’ve tried things like the ‘join’ action, and also tried manually setting a value that does a javasccript style query1.concat(query2), and tried on client-side too but can’t seem to work it out.

Any suggestions on how to join 2 arrays/lists together server-side? Or even client-side?

Expected output

[ 
{ id: 133, name: "john" },
{ id: 565, name: "joe" },
{ id: 399, name: "james" },
{ id: 102, name: "tom" } ,
{ id: 382, name: "terry" },
{ id: 3, name: "tanya" },
]

hi @ben55
you can check this link

hi @s.alpaslan,

I did try the join function, as per the images below, but it seems to just overwrite the first query.
Set up:


This was an attempt with ‘id’, but the overwrite also happens if I specify the ‘name’ field as the column to match.
I’ve tried also leaving the ‘Match Columns’ section blank, which gives an error.

Example outputs of query1, query2, and joined_set below:

Am I missing something, or is the join function only functional if trying to match two different fields?

@ben55 you can use Alias in query builder

then

image

Hi Ben, welcome to Wappler.

I believe what you will need to do is use the Custom Query builder and use Union to show results of both tables.

Thanks @brad
I have now used the Custom Query and UNION successfully replicate the two seperate queries and join them.
For anyone else who comes across this issue, my solution looked a bit like this

SELECT id, name
FROM table1
WHERE name LIKE '%t%'
UNION
SELECT id, name
FROM table2
WHERE name LIKE '%j%'

I wonder if it would be useful for Wappler to have some in-built functionality server-side for List/Array methods like append(), remove(), pop(), index(), sort() etc. :thinking:

1 Like

Glad you have it solved. Good luck with your project!