The ability to query and filter data is a cornerstone of the CXP. By leveraging the power of graph queries, you can filter your data to create meaningful segments that can be saved and used for targeted marketing campaigns. This article explains the structure and logic behind querying the database, including the use of nesting, logical operators (AND/OR/NOT), and conditions.
Operators
And
The And operator is used when all conditions must be true for a record to match the query. It narrows down the dataset by combining multiple conditions that must all be satisfied.
Example
Find customers who are older than 18 AND live in the Netherlands
Or
The Or operator is used when at least one condition must be true for a record to match the query. It broadens the dataset by including records that meet any of the specified conditions.
Example
Find customers who live in the Netherlands OR Belgium
Not
The Not operator is used to exclude records that match a specific condition. It negates the condition, ensuring that only records that do not meet the criteria are included.
Example
Find customers who do NOT have general consent.
Combined
Logical operators can be combined to create more complex queries. For example, you can use And to combine multiple conditions, Or to provide alternatives, and Not to exclude certain records—all within the same query.
Example
You want to find customers who:
-
Are older than 18 (And condition),
-
Live in either the Netherlands OR Belgium (Or condition),
-
But are NOT subscribed to your newsletter (Not condition).
-
And ensures that the customer meets the age requirement and satisfies the nested conditions.
-
Or allows flexibility in the location condition, so customers from either the Netherlands or Belgium are included.
-
Not excludes customers who are subscribed to the newsletter, ensuring you're only targeting non-subscribers.
How to think about it:
-
"AND" logic (everything must match).
-
"OR" logic (at least one must match).
-
"NOT" logic (exclude matches).
Nesting
Nesting refers to the hierarchical structuring of queries, where one query is embedded (or "nested") inside another. Nesting allows you to group conditions and apply logical operators at different levels of the query. This is particularly useful when you need to control the order of evaluation or when you want to create more granular filters.
Nesting is not the same as combining operators, but it is often used in conjunction with them. Nesting enables you to group multiple conditions under a single logical operator and then combine that group with other conditions or groups.
Key Points About Nesting
-
Flexibility: Nesting allows you to combine multiple logical operators in a structured way.
-
Clarity: By grouping related conditions, nested queries make complex filters easier to understand and maintain.
-
Performance: While nesting is powerful, deeply nested queries can impact performance. Optimize your queries by minimizing unnecessary nesting.