Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

FM 11 - Problems with correlated subquery in HAVING clause! No results

Featured Replies


Hello

I use FM Pro 11.0v3 ADV

So here is my query and  use the baselements plugin. The following code is correct, but I do not get any results. I think the oli.ID_Product in the having clause is a problem.


BE_FileMakerSQL ( "         SELECT oli.ID_Product, sum(oli."Quantity ordered")         FROM "ORD_Order_Line Items" oli         WHERE oli.Kind='Material'         AND oli.b_selected=1         AND oli.ID_Order='" & ORD_Order::ID & "'         GROUP BY oli.ID_Product         HAVING sum(oli."Quantity ordered")=(SELECT sum(ap2.Quantity) FROM Artikelposten ap2 WHERE ap2."Item Number" = oli.ID_Product) ")

 


 

Now lets remove the having clause and check if the assumption is correct.


BE_FileMakerSQL ( "         SELECT oli.ID_Product, sum(oli."Quantity ordered")         FROM "ORD_Order_Line Items" oli         WHERE oli.Kind='Material'         AND oli.b_selected=1         AND oli.ID_Order='" & ORD_Order::ID & "'         GROUP BY oli.ID_Product ")

 

Result

APS-KIT0    230

B-FC-2000P    52

 

Looks good. So far so good.

Now lets change the subquery in the HAVING clause into a non correlated sql statement. Let's test it with 'APS-KIT0'

 

BE_FileMakerSQL ( "
        SELECT oli.ID_Product, sum(oli."Quantity ordered")
        FROM "ORD_Order_Line Items" oli

        WHERE oli.Kind='Material'
        AND oli.b_selected=1
        AND oli.ID_Order='" & ORD_Order::ID & "'

        GROUP BY oli.ID_Product
        HAVING sum(oli."Quantity ordered")=(SELECT sum(ap2.Quantity) FROM Artikelposten ap2 WHERE ap2."Item Number" = 'APS-KIT0')
")

 

Result: APS-KIT0    230

Now I get a result. Nice. But why do I not get a result with the sql statement at the top. What's wromng with oli.ID_Product ?

 

I hope somebody knows :)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.