4D Blog

Home Product Logical operations on entity selections

Logical operations on entity selections

May 7, 2018

Product

The ORDA series continues! In this blog post we’ll see how to use logical operators on entity selections!

These operations allow you to get intersections, unions, or differences between two entity selections like you can with classic 4D sets.

Logical operators on entity selections example

In classic 4D, you use sets to perform logical operations on several query results. You must create a set after each query, perform the logical operation on the sets, and finally update the current selection of the concerned table with the result set. It’s a bit heavy! Thankfully, with ORDA things are becoming much lighter! Each query gives you an entity selection to which logical operators can be directly applied!

 

ORDA provides the following methods to perform logical operations on two entity selections:

– and(): get the intersection between two entity selections (entities belonging to both)

– or(): get the union between two entity selections (entities belonging to one or to the other)

– minus(): get the difference between two entity selections (entities belonging to one and not to the other)

These methods can also be applied to an entity selection and an individual entity.

Example

An example is worth a thousand words! Let’s take a look at employees and their food preferences.

CLASSIC 4D:

//A named selection "meat" is created before
// ...
QUERY BY ATTRIBUTE([Employee];[Employee]food;"fish";=;True)
CREATE SET([Employee];"fish")
USE NAMED SELECTION("meat")
CREATE SET([Employee];"meat")
UNION("fish";"meat";"result")
USE SET("result")
CLEAR SET("meat")
CLEAR SET("fish")
CLEAR SET("result")

ORDA:

Here, we have a method which receives an entity selection as parameter. We return the union of the $eatingMeat entity selection and the $eatingFish entity selection.

C_OBJECT($eatingFish;$1;$eatingMeat;$result)
 
$eatingMeat:=$1
//Get employees eating fish
$eatingFish:=ds.Employee.query("food.fish=:1";True)
//Get the union of the 2 entity selections $eatingMeat and $eatingFish
$result:=$eatingMeat.or($eatingFish)
$0:=$result

 

Discuss

Tags Database, Objects, ORDA, v17

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Avatar
Marie-Sophie Landrieu-Yvert
- Product Owner - Marie-Sophie Landrieu-Yvert joined the 4D Product team as a Product Owner in 2017. In this role, she is responsible for writing user stories and translating them into functional specifications. She also ensures that the delivered feature implementation meets the customer's needs. Marie-Sophie graduated from the engineering school ESIGELEC and began her career as an engineer at IBM in 1995. She took part in various projects (maintenance and development projects) and worked as a COBOL developer. She then moved on to work as a UML designer and Java developer. More recently, her main responsibilities included analyzing and writing functional requirements, and coordinating business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy