web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Advantage of Union query.

(0) ShareShare
ReportReport
Posted on by 56

Dear All,

Can you please give me an example of Union query in Dynamics AX 2012 R3.

what is the advantage of Union query?

How to write X++ code with using Union query.

Please give me an example.

Please give me more shed on this.

Thanks!

Arpan

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    you can not use union in x++ but you can use it in Query from AOT

    union is useful to combine multiple datasources

    msdn.microsoft.com/.../cc605991.aspx

  • @rp@n Profile Picture
    56 on at

    Thanks Hakim

    Can you please let me know when we use exactly Union query?

    Please give me more shed on this.

    Thanks!

    Arpan

  • Verified answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    in general, if you write two complex query in sql , you can union this quires.

    so we use union based on your requirements

    if it is difficult to return your data by one query in sql . you can create two quires and use union

    as the same in AOT you can create multiple datasources and use union

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Union query is useful if we want to have several datasources of same table or type on the query.

    Refer this link:

    (Union queries)

    community.dynamics.com/.../union-queries

  • @rp@n Profile Picture
    56 on at

    Thanks Chaitanya

    Sorry not understand "if we want to have several datasources of same table or type on the query".

    Please give me an example.

    Please give me more shed on this.

    Thanks!

    Arpan

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    If you check the example in the suggested link, it has two datasources of type inventtable at different stages with different ranges. It has two options with Union and UnionAll.

    where Union removes duplicated records and UnionAll keeps duplicated records.

  • Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    please go on w3 schools for basics. that could be best source as start for these concepts

    www.w3schools.com/.../sql_union.asp

    once you will have knowledge of UNION and UnionAll, I can see next question should be as following

    Difference between Union and Full Outer join. You can search and read this as well.

  • Verified answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    yes, Chaitanya is correct

    we can use it to remove duplication

  • @rp@n Profile Picture
    56 on at

    Thanks Chaitanya and Hakim

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans