BAQ for linked and unlinked jobs

Nope, that’s not right. Hold on, let me test.

Top level (or CTE or Sub) first, then union.

I think this is close, but I don’t know how to get fields into the Union. I have all three subqueries in there with the same number of fields. With the top level in place, I can save it for review:
OrdersAndJobs.baq (115.1 KB)

I think if I had the fields in the union, then they would work at the top level. I am still missing something important.


Just add them. It’s just a subquery. This text box down here gives you a hint on what the next one is looking for.

1 Like

I don’t have anything in the top query, so that box is blank. I’m so confused!

Switch it then. Make your “union” the top query, and the top query the union.



Now I am even more confused.

You gotta change the order on the subquery list too!

And put parens around the union and top levels.

1 Like

That helped. I can now get some results into my union without an error. I added the order subquery fields to the Top (Union), and to the SQUnion (Top). But how do the values from the other two subqueries get in there?
OrdersAndJobs.baq (125.1 KB)

Change them to a union as well if you’re trying to stack them all together.

1 Like

Just thinking out loud here… Put your current BAQ aside for the time being and start with a fresh simple one with a top level and two tables with just one or two fields using the union… and work on getting that right, then apply your leanings to your existing BAQ…

2 Likes

part brother GIF

I didn’t want to guide you too much :wink: , sometimes the learning happens during the struggle. But, yeah, to lean into what @Hally said, what I would probably do in your case for this is do the unioning with the bare minimum data, then on a true top level, do the joins for the informational extra stuff once so you don’t have to bring in all those fields to every union. But you’ll need to understand how to manipulate the unions, which you are learning to do now.

Just remember that query order matters, and parenthesis matter when you’re doing unions.

1 Like

Or … just write the sucker in TSQL and then use SQL to BAQ preview and see what beaks…er happens :innocent:

1 Like

You have the patience of a saint. Thank you for your time and efforts. I think I am getting it now.

I’ve tried it a few times. I didn’t really work for anything worth using it for. It doesn’t work for calculated fields, or parameters. It’s cute, but needs a LOT of work to be able to work.

I’ve only done basics also… not dug into it…

Looks like you might have figured out the union order of operations, awesome!

SQL is infinitely easier to learn by writing text in SSMS. I’ve been doing this for a very long time and if I’m doing anything remotely intricate I still write out my query in a text editor to keep my thoughts organized while I’m assembling the scattered bits of my BAQ Rube Goldberg contraption.

That’s where being somewhat fluent in SQL as text is mission critical. BAQ doesn’t actually support a lot of what we do in BAQ, we’re just able to do it because it’s not captured by injection throttling. SQL-to-BAQ always breaks window functions, for example.

Side note on learning SQL - A general reference that I recommend as much as possible is SQL Server Central’s “Stairway to SQL” series. There’s a lot in there that BAQ doesn’t support but is still helpful to know. This one covers joins and unions, and does so from basic principles instead of assuming you already know some set of basics, which is unfortunately rare for technical how-to’s.

2 Likes

That’s just because you started that way. I learned in BAQ land, and it’s like a first language vs a second. I still can visualize better with a BAQ, I just end up writing queries in SQL because 1) I have direct access to the database and 2) it’s faster.

But I can understand what’s going on with a query in a BAQ better, and I believe it’s because it’s what I learned on first.

1 Like

Haha fair :smile: I’ve done a lot of other context too, like database development. One way or another I always want the text for VCS and cattle-not-pets and all that.

Not overlooking, based on the publish dates on those stairways, I learned a long time before BAQ existed. Insert pepperidge farms, yells at cloud, so forth.

1 Like