Top 1 in a baq subquery not returning value

So I have a subquery that’s sorted by last po header date (trying to find the last purchased price)

Pretty Straightforward top

Just joining by the part number

Now, for this part number, I know there’s only 1 po out there for it, and if I convert it to a standard innerSubquery the value returns fine, but that won’t always be the case.

I’ve seen some comments on having to use RANK but that just doesn’t seem to be necessary for something this simple (and if we hit a common part I don’t want to put that additional load on the DB server)

Thoughts?

Search for @Banderson’s posts on SQL Window Functions. I think that’s what you want.

2 Likes

+1 to what Mark says above. Plus, it’s really hard to try and help when you don’t post your query.

1 Like

If you just need one field, (the last purchased price) I would do an inner sub select. But that only works for one field.

This post explains how to do that.

2 Likes

OK, I’ve tried using row_number, and it returns in SQL, but not baq, I’m missing something silly here



Mostly leaving out the screen shots that show us the rest of what you are doing. :wink:
The calculated field looks fine.

Did you add a display field to your top level query from the subquery?

1 Like

I think I may have figured it out …

image

Helps if you partition over the part number

2 Likes