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.

Apparent bug with Union clause and subquery

Featured Replies

I have found what appears to be a bug within FQL when using the union clause with subqueries.

 

The query below gives the expected result

 

SELECT d_OrganisationName
FROM ORGANISATION
WHERE a__kp_t_ORGANISATION NOT IN
  (
    SELECT a_kf_t_Organisation
    FROM ORGANISATION_CONTACT_LINK
    WHERE a_kf_t_Contact = '" & CONTACT::a__kp_t_CONTACT & "'
  )
 
which is a list all organisations that the contact isn't currently linked to
 
However, I also want to combine this result with another result, for example some default organisation:
 
SELECT d_OrganisationName
FROM ORGANISATION
WHERE d_OrganisationName = 'Default Organisation'
 
On it's own, the above query also gives the expected result, which is just 'Default Organisation'
 
However, when I put a union clause between the two queries like so
 
SELECT d_OrganisationName
FROM ORGANISATION
WHERE a__kp_t_ORGANISATION NOT IN
  (
    SELECT a_kf_t_Organisation
    FROM ORGANISATION_CONTACT_LINK
    WHERE a_kf_t_Contact = '" & CONTACT::a__kp_t_CONTACT & "'
  )

 

UNION

 

SELECT d_OrganisationName
FROM ORGANISATION
WHERE d_OrganisationName = 'Default Organisation'

 

The results include the combination of the two queries PLUS the result of the subquery, which is an id, i.e.

 

Some Org

Some Org

Default Org

OrgId1FromSubquery

OrgId2FromSubquery

 

It seems like FileMaker is seeing three result sets to UNION instead of two: the first query, the second query AND the subquery in the first query.

 

Has anyone else experienced this or have any suggestions for correcting it?

 

Thanks,

 

Alec

Could it be an order of precedence issue where the UNION throws together the SELECT for the IN plus the last SELECT and not what you expect (the result of the first SELECT plus the result of the 3rd SELECT)?  Experiment a bit with parentheses and see if that solves anything

  • Author

Many thanks for the suggestion Wim. I did try some parenthesis experiments but they didn't seem to alter the result. I think the next step is to recreate this using a MySQL database to make sure I'm not just misusing the UNION keyword. I'll report back once I've given it a go.

  • Author

Just done the same test with a MySQL database and the UNION keyword performs as expected, so this does seem to be a FileMaker-specific issue.

  • 1 month later...
  • Author

An update to this: The bug seems to be connected to the IN clause. I recently replaced an equals with an IN and the results from the sub-query appeared in the result set again. Shame =ANY doesn't work in FileMaker for a comparison.

 

I really should get this one reported.

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.