Union Query Result Set

ADX 156 Reputation points
2022-05-20T05:36:54.597+00:00

Hi,

I have a requirement like below mentioned.

Query1:

let Source = 'A'
TableA|where SourceType=Source |project ColumnA,ColumnB;
TableB|where SourceType=Source |project ColumnA,ColumnB,ColumnC;
union TableA,TableB

when i change the input parameter i.e. Source='A' then i could fetch the columns from TableA (there won't be any data in SourceType='A' in the TableB)
when i change the input parameter i.e. Source='B' then i could fetch the columns from TableB(there won't be any data in SourceType='B' in the TableA)

how could i do it in the above scenario without writing two separate queries. Because the number of output columns vary from source to source.

Please help on this.

Thanks,
Kesav

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,556 Reputation points Microsoft Employee Moderator
    2022-05-23T11:39:21.883+00:00

    Hi @ADX ,

    Thank you for posting query in Microsoft Q&A Platform.

    You can consider taking result sets of tableA and tableB in to temporary result sets using let keyword and then finally perform union on these results.

    Please check below sample implementation. Here tableA and 'tableB` are temporary in memory tables.
    204691-image.png

    204701-image.png

    Hope this helps. Please let us know if any further queries.

    -----------------

    Please consider hitting Accept Answer button. Accepted answers help community as well.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.