question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating queries with complex 'and' and 'or' combinations

See original GitHub issue

According to QueryBuilder documentation, we can define the order of logical operations using implicit and(). However, this implementation does not allow us to create complex conditions, such as (A and B) or (C and D). This comment provides a workaround, but having Realm-like chainable queries would be much nicer. Is changing existing QueryBuilder mechanics planned in future versions?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
greenrobotcommented, Oct 7, 2017

Yes, the query API subject to changes and this will be solved, of course. 😃 P.S.: if you don’t have a very big amount of entities, a more convenient work around are query filters.

2reactions
greenrobot-teamcommented, Mar 9, 2020

3.0.0-alpha1 has a preview of a new Query API that supports nested conditions. We welcome feedback! https://docs.objectbox.io/#v-3-0-0-alpha1-2020-03-09 https://docs.objectbox.io/queries#new-query-api

An example for (A and B) or (C and D):

List<User> query = box.query(
        User_.propA.equal(x).and(User_.propB.equal(y))
                .or(User_.propC.equal(s).and(User_.propD.equal(t)))
).build().find();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use a union query to combine multiple queries into a single ...
Create a union query by creating and combining select queries · On the Create tab, in the Queries group, click Query Design. ·...
Read more >
SQL VIEWS + Complex Queries, Cross Joins, Unions, and more!
In SQL, a VIEW is a virtual table. It lets you package a complex query into a single table. We will discuss several...
Read more >
10.1. Combination Queries to Consider After Unary Operators
In this chapter we will review some of the important points about the unary operators while presenting some more queries, including slightly more...
Read more >
Learn SQL: How to Write a Complex SELECT Query
Think of it as of LEGO bricks and build the query that way. · Identify all the tables you'll need in the query...
Read more >
TOP-70 Most Important SQL Queries in 2022 - ByteScout
The order by clause is used to sort the data from the table. The order by clause should always be used in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found