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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

SQL union in Query

(0) ShareShare
ReportReport
Posted on by 629

Hi everyone,

I started working with Queries recently and got this request form a user. They want to do a union between two unrelated tables (Example Customer and Vendor).

From what I have read there is no Union function in BC Queries.

pastedimage1642602754792v1.png

To get the output on the image I created a new table called "Source" with Source Type, Source_No and Source_Name as the fields.
In the OnBeforeOpen trigger in the Query I did the following to insert lines into the new "Source" Table. In other words the "Source" Table get recreated every time the Query is opened.

pastedimage1642602956733v2.png

Now I get the results that I wanted but I'm wondering if there is a better more effective way to do this?
Thank you in advance

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    I’d agree with the method you have opted for. Very limited pathways in this scenario.

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, Or create two Query first, vendor and customer, then create a new table (TableType = Temporary) and a new page to display the data in the table.

    On the trigger OnOpenPage() of the new page, using Query.Open() Method to insert data to the new table.

    However, I still think your method is simpler.

    Hope this will help.

    Thanks.

    ZHU

  • Samantha73 Profile Picture
    3,247 on at

    Tem table is better in my opinion as if two users run the report at the same time records can deleted before being displayed in the report.

  • Gert Lynge - www.dabbler.dk Profile Picture
    80 on at

    If you are OnPrem a SQL View doing the magic with a linked BC table is probably more efficient (but make sure you define a unique key that is really unique - been bit by that in the past).

    Yes, I know we are not "allowed" to suggestion cloud incompatible solutions anymore :-)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans