KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Optimizing Complex Queries
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 8, 2024

When writing queries that check for multiple conditions do not send the query like this:

$sel:=ds.Clients.query("Firstname=:1"; "John").query("Lastname=:1"; "Smith")

This sends calls to the servers and is inefficient. Queries should be written like this:

$sel:=ds.Clients.query("Firstname=:1 & Lastname=:2"; "John"; "Smith")

This only sends one call to the database.

The same is true for functions like order by. Instead of writing this:
$sel:=ds.Clients.query("Firstname=:1"; "John").orderBy("Lastname")

Write this:
$sel:=ds.Clients.query("Firstname=:1 order by Lastname"; "John")

*Code taken from 4D Summit 2020 Advanced Training by JPR