Inverse queries in Mergado#

How to work with inverse queries in Mergado#

This article explains what inverse queries are and how to use them effectively in Mergado. We will show the difference between a simple inverse query (where you just change the operator, e.g. from “=” to “!=”) and a more advanced query using MQL and the NOT operator. By the end of this article, you will be able to:

  • recognize situations where an inverse query is appropriate,
  • create a simple inverse query without knowing MQL,
  • rewrite a complex query into MQL and use NOT(...) negation to achieve the opposite result.

Context#

Normally, when working with queries, you define the products you want to target — e.g. raise the price, edit the name, or hide them. Sometimes, however, it is easier to create an inverse query — one that selects everything else except a certain group. In other words: instead of “what I want to edit,” you define “what I don’t want to edit.” This approach saves time especially when:

  • you know exactly which products should remain unchanged, or
  • you have a small group of products to keep in the output, and all others should be hidden.

Practical examples#

Typical example You manage a feed with 65,000 products. You want to keep only 5,000 specific products in the output and hide all the rest. You can approach this in two ways:

  • create a query for all 60,000 products you don’t want (very impractical), or
  • create an inverse query: “Everything except these products.” This is exactly what inverse queries are for.

When an inverse query is useful

  • you don’t want a certain group of products to be affected by a rule (e.g. you don’t want to change their name or price),
  • you want to hide everything except a certain group of products,
  • you want to manage exceptions clearly instead of long lists of conditions.

Simple inverse queries (without MQL)#

If you need to create a simple inverse query, you don’t need to use MQL right away. You can work with opposite operators directly in the basic query interface. The principle is simple: instead of a condition like “contains / is in list / =”, you use its negation.

Standard operator Opposite operator What it does
= (equals) != (not equals) Selects products with a different value
contains does not contain Selects products that do not contain the text
is in list is not in list Selects products that are not in the given list

Example 1 — reversing “contains” Original query:

CATEGORY ~CONTAINS "Zahrada"

Finds all products that have “Zahrada” in the <CATEGORY> element. Inverse query (keeps only products that do not contain this value):

CATEGORY !~ DOES NOT CONTAIN "Zahrada"

Example 2 — “is in list” vs. “is not in list” Original query (products you want to keep in the output):

ITEM_ID Is in list (101, 102, 103)

Inverse query (products you want to hide — everything except the listed ones):

ITEM_ID Is not in list (101, 102, 103)

This query picks all products except these three.

Advanced inverse queries using MQL (NOT)#

If the query is more complex (multiple conditions, AND/OR logic), we recommend using MQL and the NOT operator. This approach gives you full control over how the query is inverted.

How the NOT operator works#

In MQL, you can use NOT to negate a condition or an entire query.

Equivalence examples:

ITEM_ID != 43

is the same as

NOT(ITEM_ID = 43)
  • ITEM_ID = 43 → selects the product with ID 43
  • NOT(ITEM_ID = 43) → selects all products except the one with ID 43

How negation works (in words): NOT inverts the set — it selects everything that does not match the original query.

Steps to follow#

1) Log in to Mergado and go to query management#

  • Log in to your Mergado account.
  • Go to the Products section in the main menu.

2) Create the query#

  • The NOT operator is always added in the Custom MQL query section.
  • You can first build the query in the simple interface and then switch to the MQL section, or write the query directly in MQL.
  • Create a query of the products you want to keep.
  • Wrap the entire query in parentheses () and add NOT in front.

3) Name and save#

  • Give the query an appropriate name and save it.
  • You can then use it within rules (e.g. in a hide rule).

Practical example#

You want to keep in the output only products that:

  • have “kalhoty” in the name,
  • have the parameter color = fialová,
  • and cost more than 1100 CZK incl. VAT.

You want to hide everything else. The total number of products is about 65,000; this query finds only 2.

Steps:

  • In the query interface, switch to Custom MQL query.
  • Wrap the original query (the one defining what to keep) in () and prepend NOT. This creates an inverse query: it selects all products except those matching the original conditions. You can use it in a hide rule — only the products matching the original query will remain in the output feed.

Tips and common mistakes#

  • Don’t forget the parentheses. When combining multiple conditions, always wrap the entire original query in parentheses:

    NOT(PRODUCTNAME CONTAINS "boty" OR CATEGORY = "Doplňky")
  • Remember that NOT inverts the entire logic, not just individual parts. When combining multiple expressions with AND and OR, the result may differ from what you expect. Always test the query.

Quick recap (overview)#

Query type How to create Example
Simple inverse query Use the opposite operator CATEGORY != "Zahrada"
Inverse query with a value list Use “is not in list” ITEM_ID NOT IN (101,102,103)
Complex inverse query Use MQL and NOT(...) NOT(PRODUCTNAME CONTAINS "kalhoty" AND PRICE_VAT > 1100)

FAQ#

When does it make sense to use an inverse query?#

When you don’t want a certain group of products to be affected by a rule, when you want to hide everything except a certain group, or when you need to manage exceptions clearly without long lists of conditions.

How do I create a simple inverse query without MQL?#

In the basic query interface, use the opposite operator (e.g. != instead of =; “does not contain” instead of “contains”; “is not in list” instead of “is in list”).

What does an example of “contains” vs. “does not contain” look like?#

Original: CATEGORY ~CONTAINS "Zahrada" Inverse: CATEGORY !~ DOES NOT CONTAIN "Zahrada"

How do I create an inverse query for a list of IDs?#

Original: ITEM_ID Is in list (101, 102, 103) Inverse: ITEM_ID Is not in list (101, 102, 103) — selects everything except these three.

When should I use MQL and NOT?#

When the query is more complex (multiple conditions, combinations of AND/OR) and you need precise control over the negation of the entire query.

How does NOT work in MQL with a simple example?#

ITEM_ID != 43 is the same as NOT(ITEM_ID = 43). NOT selects all items that do not meet the condition.

Where do I write NOT?#

In the Custom MQL query section. Put the original query in parentheses () and write NOT before it.

Why are parentheses important?#

They ensure that NOT negates exactly the part you intend. With AND/OR combinations without parentheses, you risk getting a different result than expected.

Can I use an inverse query to hide everything except exceptions?#

Yes. You can use the inverse query in a hide rule, so only the items matching the original (non-negated) query will remain in the output feed.

Can I do this without knowing MQL?#

Yes — for simple cases, using opposite operators in the query interface is enough. MQL with NOT is useful when you need to negate more complex condition combinations.

🇨🇿 🇬🇧 🇩🇪 🇭🇺